I’m attempting to show HTML based upon a conditional keyword involving the file type of a given File asset. I have this sample code (simplified) in a Default Format for an Asset Listing using the following conditional keyword:
%begin_asset_file_type^eq:svg%
<img class="card-img-top img-fluid" src="%asset_url%" alt="%asset_file_type%">
%end_asset%
If the keyword is present, the logic is fine and the <img>
tag is shown for SVG files. However, the condition appears to be ignored (or resolved always as true) entirely if the keyword asset_file_type
isn’t present, resulting in HTML still being outputted. For clarity, I’m talking about when the keyword is not just empty, but non-existent; such when the Default Format is rendering an non-File Asset type like a Page which doesn’t have an asset_file_type
keyword. For any of these assets, the conditional appears ignored resulting in the the <img>
tag is outputted anyway, like so:
<img class="card-img-top img-fluid" src="[url to asset]" alt="">
(noting the blank alt
attribute, which indicates the “non-existent” keyword). I tested this further with a junk keyword like:
%begin_asset_foobar%
Foobar
%end_asset%
and Foobar
appears for all assets, because none have the keyword asset_foobar
.
Is this behaviour intentional or a bug? My expectation would be that referencing a non-existent value would evaluate to a false, causing the condition not to pass. This current behaviour causes further unexpected issues when I’m writing `%else_begin_asset_file_name%, because that logic will always evaluate as true. Is there a way of working around the issue?
The aim here is to have a single Default Format that changes HTML output very slightly depending on conditions like these. I know I could create a separate type format for each different Asset type, but this would involve repeating hundreds of lines of HTML for each and every type.
Matrix Version: 5.3.3.0