Content Container Templates, Asset Listings and Metadata pain


(Glen Lewis) #1

Hi all,

I’ve recently been upgrading all of our backend tools and creating Content Container Templates to both make things easier and remove the need for any markup to be done by our editors.

One of our commonly used elements on our pages is a “Landing Listing” which lists:

  • Asset children of the current page
  • Thumbnails (if the child asset contains one)
  • Description (if the asset Description metadata exists)
  • Asset children of the child asset

The idea of using a Content Template here is to allow the user to toggle each of the above options. The first 3 are easy and work great with an “On/Off” select, but the asset children of the listed asset is proving to be a mega issue, as it’s a nested secondary Asset Listing using the Matrix “list_current_asset_id” session variable as it’s root.

I’m not able to use a %begin_asset_metadata_page.index.asset-children% for example, as I’ve only been able to get the secondary Asset Listing to work if I create a new content container and select the Nest Content content type, and it breaks the %begin% structure as it’s outside of it’s container :frowning:

If I could %globals_asset_contents_raw:12345^with_get:root=asset_assetid% that would solve all of my problems, but unfortunately I haven’t been able to find a keyword that stays in context, like %list_current_asset_assetid% does in the nested container.

Just wondering if anyone has encountered this before and has a way around it or if anyone knows of a way to feed a nested Asset Listing the current asset ID that it’s listing by using globals_asset_contents_raw?

Thanks heaps in advance!


(John gill) #2

The issue here is that keywords starting with %globals_ are evaluated right at the end, after the page has been assembled and after the Asset Listing has finished being processed, so the context has changed and asset_ and list_current_ don’t mean what you want them to mean anymore.

I think the basic options are:

Nest Content Content Type w/ workaround

The trick here is to always nest the child asset listing and then apply your conditional statement in the Page Contents* bodycopies instead. You can’t use the %begin_asset outside, but you can use it inside to conditionally include %asset_listing% (although you’ll have to pass the value in as a parameter to use it inside).

This obviously has a performance implication, because it’ll be processing the listing even when you’re not including it.

SSJS

Instead of %globals_asset_contents_raw:12345^with_get:root=asset_assetid% you should be able to run with

<script runat=server>
var current = '%asset_assetid%';
print('%globals_asset_contents_raw:12345^with_get:root=' + current + '%');
</script>

This splits the execution into two phases - %asset_assetid% is evaluated immediately while it still means what you mean it to mean, and then the %globals_ is evaluated at the end but with the correct assetid. You could probably even do the conditional part in SSJS as well which might make it a bit tidier.

Param hack

Someone on the forums has mentioned a hack to force the immediate evaluation of asset_contents_raw, which involves a non-existent parameter like:

%nested_get_fake^append:12345^as_asset^asset_contents_raw^with_get={asset_assetid}%

or something like that (that’s untested from memory). I think that way is kinda gross, and potentially open to interference if fake is actually supplied, and you might hit issues with how many modifiers Matrix is happy to process.


(Glen Lewis) #3

Thanks for your speedy reply man, much appreciated.

Ahhhh makes so much more sense why the context changes now, cheers!

Your suggestion of the SSJS in the Page Contents definitely feels like the way to go, thanks again, I’ll jump in and have a tinker now. I’m still not entirely sure it’s feasible (Content Template setting up the toggles, first Asset Listing honouring conditionals based on those in both the current and child Asset Listings) but I’ll give it a shot :slight_smile: