jcu-eresearch / matrix-helpers

100% Unguessable™. Public bug tracker, pages, designs and helpers that make life in Squiz Matrix easier. The metaphorical red pill.
https://jcu-eresearch.github.io/matrix-helpers/
GNU Affero General Public License v3.0
3 stars 0 forks source link

[Server-side JavaScript] Keywords evaluate for the Page, not the Content Container #68

Open davidjb opened 7 years ago

davidjb commented 7 years ago

Including a SSJS block in a Content Container Template Paint Layout like so:

          <h1>Asset ID: %asset_assetid%</h1>
          <h1> From pre-eval: <script runat="server">print('%asset_assetid%')</script></h1>
          <h1> From SSJS: <script runat="server">print('%asset_assetid' + '%')</script></h1>

Ends up outputting two different asset IDs:

Asset ID: [ID of the Content Container]
From pre-eval: [ID of the Content Container]
From SSJS: [ID of the Standard Page that holds the Content Container]

This means that the keywords are evaluated before the SSJS run have one value, and the same keyword has a different value if printed out from the same SSJS block. The keywords should refer to the same 'asset' for consistency and reliability.

This inconsistency means you have to workaround the issue by using pre-evaluation of keywords to get SSJS to work; but this won't work everywhere.

davidjb commented 7 years ago

Reported at https://squizmap.squiz.net/matrix/10582