Keyword issue with CCT


(Nick Papadatos) #1

Matrix Version: 5.5.4

I’m having some issues trying to work out why the following keyword isn’t evaluating properly in the paint layout of the CCT.

example:
This doesn’t work:
%globals_asset_contents_raw:12345^with_get:root={asset_metadata_related.assets}%

But this does using ssjs
print(’%’ + ‘globals_asset_contents_raw:12345^with_get:root=’+ %asset_metadata_related.assets% +’%’);

Cheers
Nick


(Jsisk) #2

Hi Nick,

Ya, that is strange.
Can you describe more about what is is you are expecting to see and what is occurring?
It’s kind of difficult for me to see without having a look at your systems.

The only thing I can see off the bat is that you are using that is different between the two methods is that you are using “globals_asset_contents” in the first option and “globals_asset_contents_raw” in the SSJS version.

The difference being that the “raw” one will render without any Paint layout asset applied.

Maybe try updating one or the other to compare the outputs and see if that makes a difference.

Let us know how you go.

Cheers,
john


(Nick Papadatos) #3

Thanks - I updated my post but the _raw: which BTW makes no difference.
I get no results found…

Asset Lister:
Replacement Root node for the listing (must be a child of the static root node)
Get variable name = root

Now %asset_metadata_related.assets% returns the id of the related asset which acts as the root node
So theoretically %globals_asset_contents_raw:12345 (12345 being the asset lister) ^with_get:root={the id of the related metadata field} should work

but if I hard code the asset id ^with_get:root=22935 it works

Kind of weird no?

N


(John gill) #4

https://matrix.squiz.net/manuals/concepts/chapters/server-side-javascript#processing-order

Therefore, the Matrix processing order of these are as follows:

  1. Content Containers - Asset & Frontend Asset Keywords
  2. All Global Keywords
  3. All SSJS
  4. All Global Keywords in SSJS with evalkeywords="post"
  5. Parse File - Global Keywords
  6. Parse File - SSJS
  7. Parse File - Global Keywords in SSJS with evalkeywords="post"

tl;dr Execution order.

Inner {replace_keywords} aren’t processed until the %outer keyword% is processed. In your example, because the outer is a global that’s not until #2 by which time the context may have changed and asset_ doesn’t refer to what you intended (probably refers to nothing, maybe there are cases where it can refer to a different asset).

If the outer keyword was a local metadata field it’d be fine

e.g. %asset_metadata_nester^as_asset:asset_contents_raw^with_get:root={asset_metadata_related.assets}%

because that keyword is evaluated immediately in #1.


The SSJS version works because the standalone %asset_ keyword can be evaluated in #1 and then the string gets assembled in #3 and the newly formed %globals_ keyword gets evaluated in #4 or #5.


Anything of the shape %globals_asset...{asset_....}% probably won’t work, or at least won’t do what you think. It’s an extremely common trap to fall into, and I think Matrix should probably throw a warning when you try it.


(Nick Papadatos) #5

Thought as much cheers for your detailed explanation :slight_smile:

cheers
Nick