Nesting Keyword replacements, using strings returned from the main keyword replacement


#1

Matrix Version:v6.26.0

%globals_asset_children:<asset_number>^as_asset:asset_name,asset_children^replace:\{"asset_name"\:":^replace:[\[\]]:^replace:","asset_children"\:":<br><ul><li>:^replace:"\},:</li></ul>^replace:",":</li><li>%

Above is the current keyword replacement I’m using, my goal is to give a root folder as <asset_number> and return an unordered list with the sub folders as normal text, followed by the files within that subfolder as unordered lists. Below is what is currently being returned.

image

I want to be able to use the assetid listed to resolve the asset_short_name_linked essentially:

%globals_asset_children:<asset_number>^as_asset:asset_name,(asset_children^as_asset:short_name_linked)%

or

%globals_asset_children:<asset_number>^as_asset:asset_children^as_asset:asset_parent,short_name_linked%

But I don’t know how to express this in keyword replacements. I understand this would be much easier with Javascript but I am held back by guidelines etc.

Any help or advice? Thank you!


(Iain Simmons) #2

Hi @adenj,

While there probably is a way to achieve this with just keywords or a combination of keywords and server-side JavaScript, it might be better suited to an asset listing with custom grouping by parent asset (subfolders), or nested asset listings.

That would be much easier to customise, and less error prone.

Otherwise, nested keywords can get a bit gnarly:

%globals_asset_children:<asset_number>^as_asset:asset_name,{asset_children^as_asset:asset_short_name_linked}%

Typically you’d want to use ^json_decode before ^as_asset and have the whole thing in a server-side JavaScript block, to have more flexibility in how you use the data. See How to list assets using keywords and Server Side JavaScript (SSJS).

Cheers,
– iain