0

I've been struggling with stash on this project for some reason. I have a business that has multiple locations available. The locations page is filtered by location to only show what the user selects.

I have the nested lists working now thanks to Mark Croxton (@croxton). I can't seem to get my logical operators working properly though.

So I have a list that looks like this:

{exp:stash:set_list name="locations" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries 
        channel="location" 
        orderby="title" 
        sort="asc" 
        disable="categories|member_data|pagination" 
        dynamic="no"
    }
        {stash:item_entry_id}{entry_id}{/stash:item_entry_id}
        {address}
            {stash:name}{name}{/stash:name}
            {stash:street}{street}{/stash:street}
            {stash:street_2}{street_2}{/stash:street_2}
            {stash:city}{city}{/stash:city}
            {stash:state}{region}{/stash:state}
            {stash:postal_code}{postal_code}{/stash:postal_code}
        {/address}
        {stash:number}{phone_number}{/stash:number}
        {exp:stash:set_list:nested name="location_hours" context="{entry_id}" parse_tags="yes"}
            {hours_of_operation}
                {stash:status}{hours_of_operation:status}{/stash:status}
                {stash:day}{hours_of_operation:day}{/stash:day}
                {stash:open}{hours_of_operation:open format="%g:%i%A"}{/stash:open}
                {stash:close}{hours_of_operation:close format="%g:%i%A"}{/stash:close}
                {stash:range_open}{hours_of_operation:open format="%H%i"}{/stash:range_open}
                {stash:range_close}{hours_of_operation:close format="%H%i"}{/stash:range_close}
            {/hours_of_operation}
        {/exp:stash:set_list:nested}
    {/exp:channel:entries}
{/exp:stash:set_list}

I have figured out that I have to set the format of date/time stamps whilst setting the variables in stash rather than passing them through and formatting them when used. I wish there was a different way, but I can't seem to get that to work. This is why I have range_open and range_close variables. I am trying to use those in order to display the status of the location being viewed.

Per a thread in which Mark informed someone to pull the "parse_conditionals" from inner and outer lists.

{exp:stash:get_list 
    name='locations' 
}
    <div class="contentbox {name}{if '{name}' == 'XXX'} active{if:else} hidden{/if}">
        <div class="grid_3 nomargin">
            <h4>{name}</h4>
            <p>{street}<br />{city}, {state} - {postal_code}</p>
        </div>
        <div class="grid_3 nomargin">
            <h4>HOURS</h4>
            <ul style="list-style:none; padding:0;">
                {exp:stash:get_list:nested 
                    name="location_hours" 
                    context="{item_entry_id}" 
                    prefix="nested"
                }
                    <li><p class="text-left" style="font-weight:bold;padding:0;">{nested:day} : {nested:status}</p>{if "{nested:status}" == "Open"}<p style="font-size:85%;padding:0;text-align:center;">{nested:open} - {nested:close}</p>{/if}
                {/exp:stash:get_list:nested}
            </ul>
        </div>
        <div class="grid_3 nomargin {name}">
            <h4>STATUS</h4>
            {exp:stash:get_list:nested 
                name="location_hours" 
                context="{item_entry_id}" 
                prefix="inner"
            }
                {if "{inner:day format='%l'}" == "{current_time format='%l'}"}
                    {if "{inner:status}" == "Open"}
                        {if "{current_time format='%H%i'}" >= "{inner:range_open}" AND "{current_time format='%H%i'}" <= "{inner:range_close}"}
                            <p>We are currently <strong>Open</strong></p>
                        {if:else}
                            <p>We are currently <strong>Closed</strong></p>
                        {/if}
                    {/if}
                {/if}
            {/exp:stash:get_list:nested}
            <h4>CALL</h4>
            <p>Phone: {number}</p>
            <h4>EMAIL</h4>
            <p><a href="{email}">{email}</a></p>
        </div>
        <div class="clearnospacing"></div>
    </div>
{/exp:stash:get_list}

Everything seems to be working well except for the store "STATUS" segment. I don't know if this is due to looping through the nested stash list twice or not. I didn't see anything in the docs saying it couldn't be done. I have even tried to change the "prefix" for the secondary loop to "inner" rather than "nested". The odd thing is that I can retrieve the values, but the logic won't compute.

For instance, in the secondary inner list loop, the line:

{if "{inner:day format='%l'}" == "{current_time format='%l'}"}

...when just output above the logic with this:

<h1>{inner:day format='%l'} == {current_time format='%l'}</h1>

...looks like this:

Sunday == Friday
Monday == Friday
Tuesday == Friday
Wednesday == Friday
Thursday == Friday
Friday == Friday

What's even more strange is that if I output the debug string with:

<h1>{inner:day format='%l'} == {current_time format='%l'}</h1>

Then I get the following:

Sunday == Friday
Monday == Friday
Tuesday == Friday
Wednesday == Friday
Thursday == Friday
Friday == Friday
We are currently Open
Saturday == Friday

So why would outputting the variable cause it to work? If I remove:

<h1>{inner:day format='%l'} == {current_time format='%l'}</h1>

Then I don't get the expected result. I have bypassed this for now by leaving it in and commenting it out with HTML comment tags, but this is definitely NOT the solution.

1 Answer 1

1

Stash itself doesn't have modifiers for variables, such as format="". It can only capture strings from other tags. You will need to save the formatted dates when you set the Stash list if you want to use them in a comparison when getting the list.

1
  • I did that already. If you look at when I am setting the stash variables. I still had the older code from the template in there for getting them in the list. Sorry for the confusion. The comparisons still do not equate when the values do though.
    – W3bGuy
    Nov 27, 2014 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.