Problems with keyword replacement values as modifiers


(Tom Stringer) #1

Matrix Version v5.4.1

We’re having trouble using keyword replacement values as modifier arguments to pass an array of IDs to an asset list.

The current asset has a related metadata field that provides an array of IDs: %asset_metadata_related-interests% = [91456,91457]

We have an asset listing page (19689) that uses Dynamic Parameters to fetch an array of specific IDs from a GET Variable (GET Variable Name = relatedAssets).

In the current asset, we’re calling the asset listing page and passing the GET variable via a keyword string:
%globals_asset_contents:19689^with_get:relatedAssets={asset_metadata_related-interests}%

This doesn’t return any results from the asset listing.

If we manually replace the modifier argument with the output of the keyword (ie - %globals_asset_contents:19689^with_get:relatedAssets=[91456,91457]% the asset listing returns the results for 91456 and 91457 as expected.

It seems that the modifier arguments aren’t being populated using the keyword string.

We’ve tried as many different combinations as we can, but with no luck. What’s missing here?


Dynamic root node with Calendar Events Search Page asset
Keyword Execution Order in SSJS
Creating a SSJS variable from a REST resource asset
(gja) #2

I’m having a similar issue on 5.4.1.2

On the Group Level bodycopy I have

%globals_asset_assetid^neq:170915:{parent_contents}:%

But all that is being rendered is {parent_contents} and not the contents of the parent asset.

In fact I am actually wanting to do %globals_asset_assetid^neq:{parent_assetid}:{parent_contents}:%

In order to aviod recursion.
Printing %globals_asset_assetid% and %parent_assetid% - in the Group Level bodycopy returns the values I expect.
But somehow using a keyword modifier within the same body copy fails. :confused:

Should Keyword Replacement Values as Modifier Arguments be available as keyword replacements on asset listings?

Georgina.


(Bart Banda) #3

This won’t work because the {asset_metadata_related-interests} part is referring to the globals context of the keyword it’s used in, in this case it’s asset 19689, which is not where the metadata is at.

You’ve got 2 other options that I can think of:

  1. Use a nested content container instead of the Globals keyword.

  2. Use server side JS:

     <script runat="server">
     print('%' + 'globals_asset_contents:19689^with_get:relatedAssets={'+ %asset_metadata_related-interests% +'}%');
     </script>
    

But ultimately it depends on the greater context of your implementation. Can you share some more info about where you are wanting to print this? In a PL that is applied to the asset that has the related metadata field? Is that asset that you are viewing on the frontend the asset that has the metadata?


(Bart Banda) #4

Yea some keywords on the grouping format don’t work apparently: https://squizmap.squiz.net/matrix/11662

But you might as well be able to use SSJS for this?

But again, can you explain the scenario a bit more? Are you trying to print the parent asset contents if the frontend asset’s assetid is not equal to some hardcoded asset ID value? (Assuming you are grouping by parent asset’s as well that is?)


(Tom Stringer) #5

Thanks Bart

The context is pretty basic. We’re using asset lists to create a REST JSON API using data withn Matrix.

In this instance we have a course record that can have one or more “related interests” that we want to print as an array within the individual course endpoint. For example:

{
  "course_name": "Test course",
  "course_code": "234455",
  "related_interests": [
      {
          "interest": "Interest number 1",
          "interest_code": "53762"
      },
      {
          "interest": "Interest number 2",
          "interest_code": "85964"
      }
  ] }

We’ve actually managed to get around it by using embedded assets (see below), but we’d like to be able to avoid this so that we can use conditional keywords within the bodycopy (%begin_interests_are_present% print the intrests array %end_interests_are_present% etc).


Nesting Tags List in an Asset listing
(Bart Banda) #6

Thanks for clarifying.

Shame you are not on 5.4.2.0+, as the %asset_data% keyword would help with this.

Regardless, you could still simplify it a bit using either SSJS, or an asset contents keyword with a PL applied that has the asset listing in it.

So for example, something like:

related_interests": [<script runat="server">print('%' + 'globals_asset_contents_raw:19689^with_get:relatedInterests='+  %asset_metadata_related-interests% +'%');</script>],

But you could go simpler and also try to just use %globals_asset_contents_raw:19689% by itself and in the asset listing just use a dynamic set value of %frontend_asset_metadata_related-interests% as the value to source asset IDs to list from? That would work if the asset on the frontend request is the actual asset that has the metadata value for the related assets to list data from.


(Tom Stringer) #7

Ah. Good one. We’ll give that a shot.

We’re on the list to upgrade to 5.4.2 but need to get our SSO house in order first! Very much looking forward to %asset_data% - it’ll help us with a bunch of stuff.


(Tom Stringer) #8

Hi Bart

This works :ok_hand:, but a question: why are the first and last % marks separated in the print statement? I can see that the print call doesn’t work if they’re not broken out - but why does that make a difference?

ie - this works:

print('%' + 'globals_asset_contents_raw:19689^with_get:relatedInterests='+ %asset_metadata_related-interests% +'%')

but this doesn’t:

print('%globals_asset_contents_raw:19689^with_get:relatedInterests='+ %asset_metadata_related-interests% +'%')

Is it something to do with the order of processing?


(Bart Banda) #9

Yea, global keywords are processed first, so you need to separate them out in order for matrix to not try and process it prematurely, because you want the JS to run first, then the keywords. .

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