Get the asset position in a group format

Matrix Version: 5.5.4

Hi Squiz folk,

I have an Asset Lister with a Group Level 1: Parent Asset and I’m trying to get the asset position in the group.

Example:

           <div id="%group_name^lowercase^replace: :_%" class="pt-3 tabcontent <add keyword>">
             %group_listing%
           </div>

I’ve tried, %asset_is_first^eq:1:show% but that didn’t work

So add class “show” if first in the list within the group. Possible?

Thanks
NickyP

%asset_is_first% should behave how you want as along as the Asset Listing Page has List Format set to “Custom Grouping” (and possibly enable “Group assets by direct parent asset” in the Asset Grouping screen if pertinent).

I just tested (on 5.5.1.5) and got the expected results from both %asset_is_first% and %asset_page_position%

Thanks John
Your using the keywords in the default format which does work.

So you have three groups A B and C - I’m trying to get the position of group A because I want to show A but hide B and C just like tabs.

as shown here

cheers
NickyP

What about using two groups? The first creates the wrapping div, with asset positions available via the first group’s body copy. The second group renders the content.

Thanks Hugh,

When you say two groups, do you mean 2 x asset listers nested?
I’m rebuilding (streamline) the menu for this site and the fewer overheads the better…
Cheers
N

No, I meant using two custom groups within the same asset listing.

Are you using a design file for the mega menu?

No, I’m using a combo of static HTML nested with asset Listing and caching using esi: url include.
I don’t think I can achieve that level of menu structure within the design file - or not that I’m aware of.

Unless I use an esi based menu ?

Oooops. So you want to check if a group is the first group, rather than checking if an item is the first item within a group?

I’d probably reach for SSJS, in the Page Contents I’d have

<script runat="server">
var blerp = false;
</script>

then in the Group Format

<li class="
<script runat="server">
if (!blerp) print('first');
blerp = true;
</script>
">%group_name%<ul>%group_listing%</ul></li>

Kinda gross, but should be pretty flexible for things like “first group” or “first second level group in each first level group”.

2 Likes

Correct John :slight_smile:
I’m trying to check if a group is the first group not the items within the the first group.

so you can see the the embed image (inspector) the first group id=“national_variety_trials” class=“tabcontent” I was trying to add class=“tabcontent show”. I’m currently using javascript along with CSS but I thought it would be more manageable by just targeting the first group with some simple css.

Kinda weird that there’s no keyword to get the index for a group (is this correct SQUIZ?)

Your solution worked, thanks John

Cheers
NickyP

1 Like

:+1:

Belated thought, in the spirit of “don’t solve the problem you have, solve an easier problem that makes that problem go away”, depending on your markup it might be possible to replace the whole thing with a positional CSS selector.

.tabcontent:first-child instead of .tabcontent.show

(there’s no undocumented keywords in the grouping code that I can see, I think it has just never come up)

Yeah, I did already use tabcontent:first-child but because the way things get sorted in Matrix - if the sorting is out of whack then the first-child may not be the correct corresponding active tab /tab contents.
Cheers
N

Yeah, I’m after this too now. I’ll use John’s method.