Matrix Version: 5.5.6.4
I am trying to us SSJS to print out a list of assets. It is not resolving the value of the matrix variables as expected.
If I print out the value of a js variable it shows as expected.
If I print out the length of a js variable is shows the length of the string containing the matrix variable that I used to get the value for js.
If I use any sort of check to see if a variable exists it gives an answer that implies it is using the unresolved string.
I did try using the empty modifier on internal, and then settign it to external if it was empty. That seemed to work and then it didn’t. Like at first it was resolving external first, and then it wasn’t and was trying to resolve internal before it was finished with external. I assume that’s a timing thing and so not something I should rely on anyway.
I would love to just get all the metadata for each link as an object, but I don’t know how to format the SSJS to use a js variable in a matrix variable that is not a string.
I can understand that it would have trouble resolving matrix variables that are replying on js variables, but surely there is some way to do this
This is the code I have currently.
<script runat="server">
// ssjs helper functions are in #441534
var component = 'quick-links-bar',
namespace = '%asset_metadata_namespace%',
asset = %asset_metadata_quick-links-bar.links%;
if(asset.length > 0){
print(`<div class="${component}_list">`);
asset.forEach(function(id){
var name = `%globals_asset_name:${id}%`,
iconId = `%globals_asset_metadata_quick-link-button.icon:${id}%`,
attr = `%globals_asset_metadata_quick-link-button.attr:${id}%`,
external = `%globals_asset_metadata_quick-link-button.external:${id}%`,
internal = `%globals_asset_metadata_quick-link-button.internal:${id}%`,
link = (internal) ? `./?a=${internal}` : external,
linkHtml = `<div class="${component}_item">
<a href="${link}" class="${component}_button">
<div class="${component}_button-container">
${iconId ? `<div class="${component}_button-icon ${namespace}_button-icon">${helpers.icons.get(iconId)}</div>` : "" }
<div class="${component}_button-title ${component}_title">${name}</div>
</div>
</a>
</div>`;
print(linkHtml);
});
print('</div>');
}
</script>