Conditional keyword modifiers
You can use conditional keywords within content components and design parse files with any keyword. This type of keyword sets conditions that must be satisfied for displaying a section of your content. This functionality 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. Alternatively, you can define alternative content to display instead.
Conditional keywords do not work if you set the begin , else , and end conditionals across multiple components.
You must keep the conditional statement within the scope of a single component.
|
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.
Conditional keyword | Description |
---|
Conditional keyword examples
This conditional keyword prints some additional HTML around a thumbnail if a thumbnail is available on the current asset.
%begin_asset_thumbnail%
<a href="%asset_url%">
%asset_thumbnail%
</a>
%end_asset%
Using the %else_%
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%
You can also use keyword modifiers in conditional keywords.
However, the modifier only has to be applied to the %begin_%
keyword.
%begin_asset_metadata_THIS^eq:THIS%
<a href="%asset_url%">
THIS
</a>
%else_asset%
<span>
THAT
</span>
%end_asset%
The condition above will be true if the value of %asset_metadata_THIS%
equals "THIS" as the keyword condition will make it print "notempty".
If it doesn’t equal "THIS", it will print nothing, meaning that the condition will not be met.
Conditional keywords can also be nested: you can have nested conditions within conditions.
%begin_asset_metadata_THIS^eq:THIS%
<a href="%asset_url%">
%begin_asset_thumbnail%
%asset_thumbnail%
%else_asset%
THIS
%end_asset%
</a>
%else_asset%
<span>
THAT
</span>
%end_asset%
You can use the %else_begin_%
conditional keyword to print alternative content conditionally.
%begin_asset_metadata_THIS^eq:THIS%
<a href="%asset_url%">
%begin_asset_thumbnail%
%asset_thumbnail%
%else_asset%
THIS
%end_asset%
</a>
%else_begin_globals_get_THIS2%
<span>
THIS2
</span>
%else_asset%
<span>
THAT
</span>
%end_asset%
You can also use consecutive %else_begin_%
conditional keywords after each other.