Adding class for 'current' asset in listing


(Tim Davison) #1

Just wanted to share something I found today, has helped out a lot.  

 

We are currently using an asset listing to show left-hand navigation of the most recent news stories.  We contemplated using a menu design area but needed it to be sorted descending from publish date.

 

One limitation we had with the asset listing was no way to highlight the current news item being displayed.  The following keywords and modifiers solved that for us:

<li class="menu-item %asset_assetid^replace_keywords:eq:{globals_asset_assetid}:current: ^trim%">
  %asset_name_linked%
</li>

Above code will add the class 'current' to the list item for the asset currently being viewed.

 

This may not be news to any of you, but it was news to me and I couldn't find any other postings for it, so maybe this will help someone.

 

Update: this would only work with single-level navigation - there is no way to figure out parents with this method.  And will only work if the listing is being nested (either directly or in a paint layout, for example).  Otherwise the globals_ keyword never matches up properly.

 

Edit: fixed syntax error.