Conditional sections

Templates can test for certain conditions and generate different output according to the result.

{%?xxx%} tests if the xxx parameter has been set and if so, generates the output up to the next {%ENDIF%} tag. {%??xxx%} does the same, but the xxx parameter must also evaluate to a boolean true.

{%!xxx%} does the opposite, generating output if the parameter has not been set. {%!!xxx%} does the same, but the xxx parameter must also evaluate to a boolean false.

All of these can also have an {%ELSE%} clause.

 

The following example checks if a feed item has an author. If it does, it outputs the author's name [1], wrapped in a mailto: link if the author's email address has been given.

{%?CHANNEL-METADATA% author}            test if the channel has specified an author
    {%?CHANNEL-METADATA% author/email}  test if the author's email address was given
        <a href="mailto:{%@%}">           - yes: start the mailto: link
    {%ENDIF%}
        {%CHANNEL-METADATA% author}     insert the author's name/email/URL
    {%?CHANNEL-METADATA% author/email}  test if the author's email address was given 
        </a>                              - yes: close the mailto: link
    {%ENDIF%} 
{%ELSE%}
    No author was specified!            insert this if no channel author was specified
{%ENDIF%}
Warning
This example contains some potential problems which are discussed here, together with how to work around them.

Note the use of {%@%} as a shorthand for the parameter evaluated in the previous {%?xxx%} or {%!xxx%} tag.