Open PaulineLawrey opened 7 years ago
Reported at https://squizmap.squiz.net/matrix/10711.
Response is that conditional keywords are only supported in the assets that generates PHP content file at the compile time (Bodycopy Container/Design). Essentially, conditionals get converted into if
statements in PHP, which doesn't fly in this context because keyword replacements are string-parsing only.
I doubt we'll see a resolution to this one; the code base which powers all these replacement layers is already spaghetti. So, let's hope for #55 instead and we can do away with keywords entirely.
In a Content Container Template Paint Layout, I tried using conditional keywords in my SSJS output. However, although the conditional keywords were removed from the final output, the content inside the conditional was still included, even though the condition was false. This behaviour is similar to how Conditional Keywords in a Design parse file weren't evaluated; at least before that feature was implemented via https://squizmap.squiz.net/matrix/9732.
Here's an simplified example:
Gives an output of:
noting the conditional being printed out of SSJS is being ignored.
For note, the reason that a SSJS
if
statement can't be used in this instance is because this Paint Layout's SSJS is being used to generate keywords that get processed in the output. The Content Container Template has a metadata schema of related items, which is can be evaluated on starting the SSJS block, but that list of related items can be an arbitrary length and various keywords need to be evaluated on each of the assets in the list. So, in the Paint Layout, I can use aforEach
statement to iterate over the list of IDs, but can't get evaluate their keywords.This issue would be resolved if a SSJS API was available (eg see https://squizmap.squiz.net/matrix/10541), resolving the messy state of getting data in or out of SSJS.