Blog

Squiz Matrix and the Power of list_current_asset_id

Thu, Jul. 28, 2011

The list_current_asset_id feature of Squiz Matrix has always been somewhat complex and confusing to understand and setup correctly. It is extremely powerful and helps eliminate common problems such as attaching a thumbnail to an asset or printing out child asset info in an asset listing. Here I want to provide an easy to follow tutorial on how exactly to use this feature and why you would want to use it.

For some reason list_current_asset_id is still an undocumented feature on the Squiz Matrix Manuals website.

Why Use?

The main reason that I love using list_current_asset_id is because I like to be able to store images in relation to the asset that they will be used in. So, if I have a Standard Page Asset that includes images in the markup I don't always want to store those images in the Media Folder or elsewhere because I feel there is a disconnect between the content that is associated with that page (others might feel different about this, that is fine). Using an Asset Listing Page you can list the contents and attributes of your Standard Page assets, but how are you going to show the image that is a child of the Standard Page? That is where list_current_asset_id comes into play.

  • Listing

As you can see, I have structured each one of my pages with images as children assets. Currently my Image Assets are TYPE_1 links. If you structure is going to show in a navigation you might want to switch them to TYPE_2.

  • Asset Map

1. Parent Asset Listing

Continuing from the example above, create a new Asset Listing Page, this will be our "Parent" asset listing. Setup your asset listing like the following:

  • Asset Types to List: Standard Page
  • Asset Statuses to List: Live
  • Root Nodes: Leave blank if assets are children of asset listing
  • Direct Links Only: Yes (makes things faster when listing)

2. Child Asset Listing

This is where the magic happens, the child asset listing. Create a second Asset Listing Page. This can be created outside of your site or where ever you like since it will not be viewed directly. Create this new Asset Listing Page then configure it will the following:

  • Asset Types to List: Image
  • Asset Statuses to List: Live
  • Root Nodes: Your site asset
  • Direct Links Only: Yes (makes things faster when listing)
  • Dynamic Parameters: Replacement Root node for the listing: list_current_asset_id
  • Dynamic Params

In the default format asset of this child asset listing you can place the code to print out your image:

<img src="%asset_url%" height="%asset_attribute_height%" width="%asset_attribute_width%" alt="Your image" />

3. Hooking the two together

Next you need to edit the default format asset of your parent listing. Create a new Nested Content div. Once that has been created, nest your Child Asset Listing. Preview the parent asset listing and you should now see all of your child images listed along with any other additional keywords you might want to add, just make sure to create another RAW HTML div to add these keywords in.

  • Dynamic Params

Conclusion

Using list_current_asset_id is extremely powerful but you have to know how to use is properly and get the setup right. There are many more powerful things you can do with this, we have just scratched the surface of what it can do. If you want to see the working example take a look at the apps and projects pages, both of which are using list_current_asset_id.

Just remember, it takes two asset listings. Good luck!

Nicholas Hubbard
Owner

Comments

Robin
Jul 28, 2011
Good way to replace the thumbnail link but it takes longer to generate the page.
Paul Wojciechowski
Jul 29, 2011
Great tutorial! I use list_current_asset_id in the similar way, but I'm very curious how looks more complicated usage...
Nicholas Hubbard
Jul 29, 2011
I will be writing up another blog post about how you can use list_current_asset_id to display how many comments you have in a blog post, or how many images you might have in a gallery. Good stuff coming soon.
John Lockhart
Sep 14, 2011
Thank you so much for this really helpful tutorial! Really opens up some interesting possibilities.
Bart Banda
Nov 5, 2011
Yes, this is a good trick and should get added to the manuals. You can also achieve the above by just using 1 asset listing and using grouping. Just set it to list Page Contents assets and Images instead of Standard Pages and you can configure the format in the group type format for the output that the Standard Pages need. Not sure which one will take longer to generate though.
Nicholas Hubbard
Nov 7, 2011
Good tip about grouping! I just know that using list_current_asset_id gives you more flexibility because of the options that having both asset listings give you.
Jon Luker
Sep 22, 2013
Fantastic article, thank you Mr Hubbard. Your writings on the undocumented and obscure have saved the day for me yet again. My example use: I needed to create a JSON feed from a folder of assets - each of which has child assets, each with their own metadata. My feed needed to dig deeper to pull that child data in too. I clearly needed to nest in a second asset lister - but the darned thing stubbornly refused to dynamically set its root node to the "current" asset... I've just found and used your technique above. My second asset lister was working immediately, I have full access to those child assets and all their metadata and properties. Brilliant.

Add Comment