https://matrix.squiz.net/manuals/concepts/chapters/server-side-javascript#processing-order
Therefore, the Matrix processing order of these are as follows:
-
Content Containers - Asset & Frontend Asset Keywords
- All Global Keywords
- All SSJS
- All Global Keywords in SSJS with
evalkeywords="post"
-
Parse File - Global Keywords
-
Parse File - SSJS
-
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.