2

So building on the answers from my previous question, I'm trying to cache the main navigation on my site.

As I understand it, the principle is to cache everything in one big chunk and then use the stash:nocache tag to except the conditionals used for the active state.

The relevant part of my code is:

{exp:stash:set name="full_nav_cache" parse_tags="yes" parse_conditionals="yes" output="yes" save="yes" refresh="180" replace="no" scope="site"}
    {exp:navee:custom nav_title="main-nav" wrap_type="none"}
        <li class="{stash:nocache}{if '{site_url}{segment_1}/' == {/stash:nocache}'{link}'{stash:nocache}}selected{/if}{/stash:nocache}">
    {/exp:navee:custom}
{/exp:stash:set}

However, it seems like the {segment_1} variable is still parsed when the cache is saved. In the database I'm seeing:

<li class="{if '{site_url}/products/' == 'http://mysite.com/products/'}selected{/if}">

But I was expecting:

<li class="{if '{site_url}{segment_1}/' == 'http://mysite.com/products/'}selected{/if}">

which would then get parsed on the page load. Is the the expected behavior?

3

If you use that code in an EE template (rather than a Stash embed) then EE will parse {segment_1} early, before tags are run and before Stash can escape it.

See step 1 here: http://loweblog.com/downloads/ee-parse-order.pdf

The good news is you can access any global variable or snippet as a tag like this:

{exp:stash:get name="segment_1" type="snippet"}

Thus:

{exp:stash:set name="full_nav_cache" parse_tags="yes" parse_conditionals="yes" output="yes" save="yes" refresh="180" replace="no" scope="site"}
    {exp:navee:custom nav_title="main-nav" wrap_type="none"}
        <li class="{stash:nocache}{if '{site_url}{exp:stash:get name="segment_1" type="snippet"}/' == {/stash:nocache}'{link}'{stash:nocache}}selected{/if}{/stash:nocache}">
    {/exp:navee:custom}
{/exp:stash:set}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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