Conditional nested asset listing


#1

**Matrix Version:**5.5.02

Hello,

I have an asset listing (AL1) which lists the direct children under a standard page.
I wish to have a second asset listing (AL2) to list the children of each node in AL1, only if a metadata field is set to “yes”.

So I have printed out AL1. Within the default format of AL1, I insert AL2 with %globals_asset_contents:12345% because it is conditional.

In AL2, I need a dynamic root node, but “Replacement Root node for the listing”, Session variable name, list_current_asset_id combination that I have used in the past is not working as expected and I am returning no results.

If I remove the condition in AL1, and have a normal nested content container with AL2, the dynamic root node in AL2 works correctly.

How can I fix this? Is there a better way of doing this?

Edit: I should mention that there will also be two different versions of AL2 controlled by metadata


(John gill) #2

You can use a Nested Content Container and put the conditional keyword inside AL2’s Page Contents. You take a theoretical performance hit by doing unnecessary work for the AL2 instances that don’t render anything, but it’s unlikely to be an issue.

That said, I’ve mostly given up on AL-in-AL nesting in favour of SSJS (at least for the nested listing). It doesn’t cover all possible use cases, but where it’s sufficient I find it much, much tidier. Removes a whole category of potential issues around scoping and Matrix cache (if that’s still on).