Conditional Keywords
Last Updated: 24 Oct 2016
Conditional Keywords can be used within Content Containers and Design parse files with any keyword as conditions that must be satisfied for a section of your content to be displayed. This is similar to the Conditional Keywords function available on Paint Layouts.
The main difference with standard conditional keywords is that the condition is true if the keyword is not empty and false if it is empty or '0'. If the condition is not satisfied, the appropriate section of content is not displayed to the user or alternative content can be displayed instead.
Using Conditional Keywords
Conditional keyword replacements allow you to configure the content so that only certain areas will be visible if a keyword is not empty and are as follows:
- %begin_<full_keyword>%: if the <full_keyword> is NOT empty AND NOT equal to '0', the content that is between this keyword and the next conditional keyword will be shown.
- %else_begin_<full_keyword>%: if the previous <begin_> or <else_begin_> condition was evaluated as empty or equal to '0' AND this <full_keyword> is NOT empty AND NOT equal to '0', the content that is between this keyword and the next conditional keyword will be shown. This keyword replacement is optional.
- %else_<keyword_format>%: if all other previous <begin_> and <else_begin_> conditions were evaluated as empty or equal to '0', the content that is between this keyword and the keyword %end_<keyword_format>% will be shown. This keyword replacement is optional.
- %end_<keyword_format>%: use this keyword to indicate where the conditional content ends.
<keyword_format>
is simply based on the type of keyword you started the conditional block with. So for example, if you start with something like %begin_globals_asset_metadata_value%, the <keyword_format>
would be globals
.
Examples
This conditional keyword will print some additional HTML around a thumbnail if there is a thumbnail available on the current asset.
%begin_asset_thumbnail% <a href="%asset_url%"> %asset_thumbnail% </a> %end_asset%
Using the %else_<keyword>% keyword, you can print alternative content if the condition is not met (if the keyword is empty).
%begin_asset_thumbnail% <a href="%asset_url%"> %asset_thumbnail% </a> %else_asset% <span class="no-thumbnail"> <!--No Thumbnail set for this asset.--> </span> %end_asset%
Keyword modifiers can also be used in conditional keywords, however the modifier only has to be applied to the %begin_<keyword>% keyword.
%begin_asset_metadata_foo^eq:foo% <a href="%asset_url%"> FOO </a> %else_asset% <span> BAR </span> %end_asset%
The condition above will be true if the value of %asset_metadata_foo% equals "foo" as the keyword condition will make it print "notempty". If it doesn't equal "foo" it will print nothing, meaning that the condition will not be met.
Conditional keywords can also be nested, so you can have nested conditions within conditions.
%begin_asset_metadata_foo^eq:foo% <a href="%asset_url%"> %begin_asset_thumbnail% %asset_thumbnail% %else_asset% FOO %end_asset% </a> %else_asset% <span> BAR </span> %end_asset%
The %else_begin_<keyword>% can be used to conditionally print alternative content.
%begin_asset_metadata_foo^eq:foo% <a href="%asset_url%"> %begin_asset_thumbnail% %asset_thumbnail% %else_asset% FOO %end_asset% </a> %else_begin_globals_get_foo2% <span> FOO2 </span> %else_asset% <span> BAR </span> %end_asset%
You can also use consecutive %else_begin_<keyword>% after each other.
Conditional keywords can not span across multiple content containers. The begin, else, and end keywords must all reside within the same content container for them to work.