Streamlining process to get metadata from multiple folders - Squiz/JS question


#1

Picking up from here, I am now trying to streamline the process further. Instead of creating multiple variables, then combining together at the end to create the required output, I am trying to streamline the process where I can simply add folder numbers, and get the output. However output is giving me the string with each folder ID, instead of the output from the string.

See below:

var numbers = [123456, 234567, 345678];
var data = [];

for (let num of numbers) {data.push(`%globals_asset_children:${num}^json_decode^as_asset:asset_name,asset_assetid,asset_url,asset_published_short,asset_data_metadata,asset_data%`);}  

// Show output:
print(JSON.stringify(data,null,2));

Example:
"globals_asset_children:123456^json_decode^as_asset:asset_name,asset_assetid,asset_url,asset_published_short,asset_data_metadata,asset_data", "globals_asset_children:234567^json_decode^as_asset:asset_name,asset_assetid,asset_url,asset_published_short,asset_data_metadata,asset_data", "globals_asset_children:345678^json_decode^as_asset:asset_name,asset_assetid,asset_url,asset_published_short,asset_data_metadata,asset_data"

Thoughts/suggestions would be appreciated from those who dabble within the squiz/JS realm?

Thanks again.


(Nic Hubbard) #2

Was there a reason that you couldn’t use an Asset Listing here?


#3

Hi Nic,
Unfortunately the Squiz Asset lister is a lot slower to compile.
I have been working on providing records in a SPA (single page application) user experience, and for this to work, it needs to have a seamless interaction when a user interacts with the page.


(Bart Banda) #4

If you know the asset IDs ahead of time, you’re best of hardcoding the global keywords as what you have above won’t work because the JS will execute independently to the global keywords, so you can’t mix and match the JS with the global keyword rendering like that, check out https://matrix.squiz.net/manuals/concepts/chapters/server-side-javascript#processing-order for more info on that.