2

Can i nest simple conditionals and are nested simple conditionals still parsed early?

What happens when nesting an advanced conditional inside a simple conditional?

(wiki answer)

1 Answer 1

2

the following template will generate an error because neither the "foo" or "bar" module or plugin exist.

Nested simple conditionals
The "foo" error will not show up, because the two nested conditionals are both simple conditionals.

Advanced conditional
The second block has a nested advanced conditional (it tests for two conditionals, last_segment AND segment_3) and thus the whole block is seen as being advanced conditionals, including the outer. The whole block will be parsed, generating an error for the non-existant "bar" extension.

Hands-on: Try removing the AND ... part from the advanced conditional to test the difference (no more error). And try adding foo/bar to the browser url (example.com/group/template/foo/bar), and see the "foo" error appear.

Conditional test
{if last_segment != "foo"}
  {if segment_3 == "foo"}
    {exp:foo}{/exp:foo}
  {/if}
{/if}

{if last_segment != "foo"}
  {if segment_3 == "foo" AND segment_3 =="bar"}
    {exp:bar}{/exp:bar}
  {/if}
{/if}

Tip: Tags in advanced conditionals are always being parsed, they are just discarded before displaying the page. if you're not sure what is parsed, try enabling template-debugging to see which tags do get parsed. Alternatively you could add a tag for a non-existing plugin "foo" and see if the page generates an error, that way you know that the part is being parsed :-)

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.