2

I have dynamic navigation based on the current page in my header snippet. I have it setup like this:

    {if segment_1 == "" OR "{404}" == "true"}
        {exp:structure:nav start_from="/wat-doen-wij" max_depth="1" current_class="active"}
    {/if}

    {if segment_1 == "wat-doen-wij" AND "{404}" != "true"}
        <div class="subnav_wrapper">
            {exp:structure:nav start_from="/wat-doen-wij" max_depth="1" current_class="active"}
        </div>
    {/if}

    {if segment_1 != "" AND segment_1 != "wat-doen-wij" AND segment_1 != "zoekresultaten" AND segment_1 != "waarbij-helpen-wij" AND "{404}" != "true"}
        <div class="subnav_wrapper">
            {exp:structure:nav start_from="{freebie_1}" max_depth="1" current_class="active"}
        </div>
    {/if}

On my 404 template I use the following statement to set my 404 variable:

{preload_replace:404="true"}

However, this breaks all my other pages. How can I fix this? I need to know which template I am currently on. Can I do it based on header infomation? I can't use {segment} because segment_1 could be anything.

1

{preload_replace:404="true"} will never work as you are using it because it's not passed to the header. This variable is only available for use in the same template... docs for Preload Text Replacements are here.

Preload Replacements act as a straight string replacement for use later in the same template.

Instead use this in your 404 and header templates:

IN 404 TEMPLATE:

{embed="includes/header" 404="true"}

IN HEADER TEMPLATE:

{if segment_1 == "" OR "{embed:404}" == "true"}
    {exp:structure:nav start_from="/wat-doen-wij" max_depth="1" current_class="active"}
{/if}

{if segment_1 == "wat-doen-wij" AND "{embed:404}" != "true"}
    <div class="subnav_wrapper">
        {exp:structure:nav start_from="/wat-doen-wij" max_depth="1" current_class="active"}
    </div>
{/if}

{if segment_1 != "" AND segment_1 != "wat-doen-wij" AND segment_1 != "zoekresultaten" AND segment_1 != "waarbij-helpen-wij" AND "{embed:404}" != "true"}
    <div class="subnav_wrapper">
        {exp:structure:nav start_from="{freebie_1}" max_depth="1" current_class="active"}
    </div>
{/if}
| improve this answer | |
  • I have found a solution in the meantime, but thank you for your response. I will use this in the future. However, I use snippets for my header and footer. Would this also work for snippets instead of embedded templates? – Maarten Kuiper Mar 5 '13 at 12:04
  • Please post your solution as an answer to your question for others with this issue to find. I don't use Snippets for header/footer so can't answer that part of your question. Best test is to try it. Feel – Anna_MediaGirl Mar 5 '13 at 16:00
0

Not really solving your problems here but I think you need to be aware that you've got 3 nav tags inside advanced conditionals, just for your 404 'problem'.

Doing it this way, all the nav tags are going to get parsed, always. This is adding a bunch of overhead (queries, template parsing etc) to every single page load on your site.

There are lots of articles about this if you google 'ExpressionEnging parse order' but here's one to get you started.

IMO a 404 doesn't need a subnav, it just needs to obviously tell the user they are on a broken page. Main navigation, yes. Sub navigation of any section they might be on, not really.

| improve this answer | |
  • I am aware of the parse order, but I will look into it, thanks for mentioning it. The page does require a subnav, mainly because of the way the homepage is setup. Sadly I can't just exclude it on the 404 page, because if I could do that I could also include it.. – Maarten Kuiper Mar 4 '13 at 9:22

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.