Is it possible to do conditionals within paint layouts on global keywords? It always evaluates to false, for example:
Is it possible to do conditionals within paint layouts on global keywords? It always evaluates to false, for example:
You should be, but you can also try and do it with just basic keyword conditions like this:
<link rel="canonical" href=" %begin_globals_asset_metadata_Global.Canonical% %globals_asset_metadata_Global.Canonical_asset_url%/%globals_asset_web_path% %else_globals% %globals_asset_url% %end_globals%">
This might be related to this topic.Is it possible to use a global variable in a conditional?
Something like this:
%begin_asset_name^eq:%globals_site_metadata_config.siteLang%:1:0%
Asset name is equal to the global site siteLang metadata
%end_asset%
You can, but you need to use the ^replace_keywords modifier method:
%begin_asset_name^replace_keywords:eq:{globals_site_metadata_config.siteLang}:1:0% Asset name is equal to the global site siteLang metadata %end_asset%
Thanks Bart.It really makes sense and I’m expecting it to work but for some reason it’s not.
If I try running this code:
I see the following output
%asset_name^replace_keywords:eq:{globals_site_metadata_config.siteLang}:1:0%
%begin_asset_name^replace_keywords:eq:{globals_site_metadata_config.siteLang}:1:0%
Asset name is equal to the global site siteLang metadata
%end_asset%
It looks like asset_name and globals_site_metadata_config.siteLang doesn’t match, the conditional keeps evaluating to true
0
Asset name is equal to the global site siteLang metadata
Tried using basic keyword conditions... it always evaluates to true, even when the related metadata field is empty, which should be false.
I had to resort to changing the metadata field from a related asset field to a text field, using a default value in the text field of %asset_url%
<link rel="canonical" href="%globals_asset_metadata_Global.Canonical.URL%">
Not ideal but it works for now.
Seems squiz cannot do paint layout conditionals on related asset fields, is this a limitation of the CMS, maybe be fixed in future? we are running 5.1.3.0
Not sure Gavin, that should work, but may be an old bug in your version only, we'd have to replicate it in latest to see if it's still there, but should be possible.
gabric098, that's weird as well, I should be able to replicate that easy to see if that's an issue in latest matrix, what version are you using?
Hmm strange, I can replicate but not sure why it wouldn't work, I'll get it investigated by the devs and report back.
In the meantime, I was able to workaround it using the reverse check using:
%begin_globals_site_metadata_config.siteLang^replace_keywords:eq:{globals_asset_name}:1:0% Asset name is equal to the global site config.siteLang metadata %else_asset% Asset name NOT equal %end_asset%
Can you try this on your end to see if it works?
Actually, I think you have to use globals on the asset name, so try this:
%begin_globals_asset_name^replace_keywords:eq:{globals_site_metadata_config.siteLang}:1:0% Asset name is equal to the global site siteLang metadata %end_asset%
Gavin, I think you are getting a bug that has been fixed in 5.3.2.1 and 5.2.9.1 (https://squizmap.squiz.net/matrix/8859)
When using begin/else/end keyword conditions on keywords that are not created via the Conditional Keywords screen on Paint layouts, it seems you can't use keyword modifiers on them.
For example, if you print the following in a standard page:%begin_globals_get_SQ_DESIGN_NAME^eq:bob:PRINT:% <p>STUFF 1</p>
%end_globals%It works fine, STUFF will only get printed if ?SQ_DESIGN_NAME=bob is in the URL.
But if you put that inside a type format of a paint layout, it will never print, as soon as you add a keyword modifier on it.
So seems that keyword modifiers on conditional keywords on type formats of paint layouts don't work.
Actually, I think you have to use globals on the asset name, so try this:
%begin_globals_asset_name^replace_keywords:eq:{globals_site_metadata_config.siteLang}:1:0% Asset name is equal to the global site siteLang metadata %end_asset%
Hi Bart and thanks for your response.
This syntax does actually work as expected.
Unfortunately my use case is a bit more complex and I have to use the asset_name instead of the global_asset_name to implement what I have in mind.
I'm using an asset listing and I need to use that conditional in a bodycopy so I really need to compare the current asset name, not the global_asset_name.
In the meantime I found a workaround but it would be nice to being able to use the conditionals in asset listings.
This is my use case in details:
I have a Standard Page asset called mylist, the url will be something like http://thehost.tld/mylist
inside this page I embed an asset listing which is listing some assets and there I want to put the above mentioned conditional.
Thanks for your help.
Gab