3

Here's some code I'm using to generate Breadcrumbs on my site. Unfortunately the client has quite specific requirements in terms of URLs, so I've had to play around with Crumbly's tag a little using an If statement:

{if segment_1 == "search"}
    {exp:crumbly:breadcrumbs custom_url:pattern="template_group/template/ignore"}
{if:elseif segment_2 == "search"}
    {exp:crumbly:breadcrumbs}
{if:else}
    {exp:crumbly:breadcrumbs}
{/if}

    {if count > 1}
        {if 1 == 1}
            <span class="divider">&raquo;</span>
            <li>
                <a href="{if count != total_results}{breadcrumb_url}{if:else}#{/if}">
                    {breadcrumb_title}
                </a>
            </li>
        {/if}
    {/if}
{/exp:crumbly:breadcrumbs}

Unfortunately, EE's template, when saved, warns me this:

{exp:crumbly … No closing tag found. Note: some tags do not require closing. Please consult the module's documentation if you experience problems.

However I hope you can see it should just be a warning, as the closing tag is present.

Here's the main problem. When I load the page, I get this:

Parse error: syntax error, unexpected T_ELSEIF in /nfs/c09/h02/mnt/135913/domains/mysite.com/html/system/expressionengine/libraries/Functions.php(683) : eval()'d code on line 75

Any ideas?

4

For deeper understanding, read about Rendering Stages in EE user guide. Advanced conditionals are processed after module tags.

Putting it simply, exp:crumbly:breadcrumbs is processed before if statements, so EE engine is receiving 3 exp:crumbly:breadcrumbs opening tags and just one closing tag.

There are 2 possible solutions:

1) Have separate code for each if (note that actually 3 tags will be processed, but just 1 displayed)

2) Use IfElse or Switchee module (this is the approach I'd choose)

2
  • Thank you... I'm now using Switchee successfully. It still gives the Template warning, but it works perfectly otherwise. – Jack Feb 15 '13 at 14:15
  • Template warning is resulted by basic check for closing tags... the checker does not try to parse the tags, it's only looking for closing match - so you can ignore the warning. – Yuri Salimovskiy Feb 15 '13 at 14:23
3

You can't separate heading and closing tags by {if} statements like that. I've never used Crumbly specifically, but with ExpressionEngine native tags, BOTH the open and closing tags need to be within the `{if} area to be properly evaluated, so this should work

{if segment_1 == "search"}

    {exp:crumbly:breadcrumbs custom_url:pattern="template_group/template/ignore"}
     {if count > 1}
        {if 1 == 1}
            <span class="divider">&raquo;</span>
            <li>
                <a href="{if count != total_results}{breadcrumb_url}{if:else}#{/if}">
                    {breadcrumb_title}
                </a>
            </li>
        {/if}
    {/if}
    {/exp:crumbly:breadcrumbs}

{if:elseif segment_2 == "search"}

    {exp:crumbly:breadcrumbs}
     {if count > 1}
        {if 1 == 1}
            <span class="divider">&raquo;</span>
            <li>
                <a href="{if count != total_results}{breadcrumb_url}{if:else}#{/if}">
                    {breadcrumb_title}
                </a>
            </li>
        {/if}
    {/if}
    {/exp:crumbly:breadcrumbs}

{if:else}

    {exp:crumbly:breadcrumbs}
     {if count > 1}
        {if 1 == 1}
            <span class="divider">&raquo;</span>
            <li>
                <a href="{if count != total_results}{breadcrumb_url}{if:else}#{/if}">
                    {breadcrumb_title}
                </a>
            </li>
        {/if}
    {/if}
    {/exp:crumbly:breadcrumbs}

{/if}

but this WILL NOT

{if segment_1 == "search"}
    {exp:crumbly:breadcrumbs custom_url:pattern="template_group/template/ignore"}
{if:elseif segment_2 == "search"}
    {exp:crumbly:breadcrumbs}
{if:else}
    {exp:crumbly:breadcrumbs}
{/if}

    {if count > 1}
        {if 1 == 1}
            <span class="divider">&raquo;</span>
            <li>
                <a href="{if count != total_results}{breadcrumb_url}{if:else}#{/if}">
                    {breadcrumb_title}
                </a>
            </li>
        {/if}
    {/if}
{/exp:crumbly:breadcrumbs}
0

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.