Dynamic root node value in menu normal design area


(Oliver Kass) #1

Matrix Version: 5.34

Hi folks,

Does anyone know a way of pulling through a metadata value to populate the root_node value tag in the menu normal design area?

I’m trying to make the value dynamic so I can set a root node via metadata at page level rather than in the design itself.

I was attempting something like this:

<MySource_AREA id_name="menu" design_area="menu_normal">
          <MySource_SET name="settings.class.normal" value="" />
          <MySource_SET name="settings.class.current" value="selected" />
          <MySource_SET name="settings.class.hierarchy" value="hier" />
          <MySource_SET name="root_node" value="asset_metadata_root.node^as_asset:asset_assetid" />
          <MySource_ASSET>
            <a href="<MySource_PRINT var="asset_link" />" class="<MySource_PRINT var="settings.class" />">
              <MySource_PRINT var="asset_short_name" />
            </a>
          </MySource_ASSET>
          <MySource_DIVIDER><br/></MySource_DIVIDER>
        </MySource_AREA>

It appears that the value field doesn’t accept keywords though as it’s throwing up errors when submitting the parse file.

Thanks

Oli


Optional Secondary Menu
(Bart Banda) #2

I don’t believe you can. Instead of using a design area, you could use an asset listing instead?


(Oliver Kass) #3

I feared that might be the case… How easy is it to assign a root node to a listing via a metadata value? Can you just use a keyword in the Dynamic Parameters? Something like:

%asset_metadata_root.node^as_asset:asset_assetid%


(Bart Banda) #4

Yep, but use %globals_asset_metadata_root.node% instead.

Also, have a look at https://matrix.squiz.net/tutorials/2016/how-to-create-a-dynamic-asset-listing-using-keywords


(Oliver Kass) #5

Thanks Bart. That tutorial was ideal. Have figured that out. One more question…is there a way in Matrix to show the active asset in the list the same way menu_normal would i.e. a way to replicate “settings.class.current”?


(Bart Banda) #6

Shame you are not on 5.3.5.0, the frontend asset keyword would be ideal for that: https://matrix.squiz.net/manuals/keyword-replacements/chapters/frontend-asset-keywords

You might be able to do some keyword modification on the current URL to see if it matches the current asset being listed, or with keyword conditions?


(Oliver Kass) #7

Always an upgrade away :slight_smile:

You’re right though, there probably should be a way with conditions or modifiers. I’ll have a play and come back if I’ve figured it out or reach a dead end.


(Oliver Kass) #8

OK I can get pretty close with this but unfortunately it shows all list items as active. The condition is just on the current asset being true so it gives the active class to all assets in the list on every page :frowning:

<li class="%globals_asset_url^replace_keywords:eq:{asset_url}:active:normal%">%asset_name_linked%</li>

Any ideas if it can be tweaked to only give the active class to the asset the user is on?


(Charlotte Westney) #9

I’m struggling with this exact thing at the moment! I’m on 5.3.4.0

I can get this conditional keyword to work:
%begin_asset_assetid^eq:910638%

So I can get a class output only when viewing page 910638
But if I try and match the asset to the actual global asset, the keyword condition breaks and it shows for all pages.

%begin_asset_assetid^replace_keywords:eq:{globals_asset_assetid}%

I’ve checked that last keyword over and over, why isn’t that working?!


(Oliver Kass) #10

I guess because it’s in the default type format for the asset listing - mine is anyway. So there will always be one true asset in the nav which applies the class to all the others. There needs to be a way of current asset only…it looks like the frontend asset cover this…

It’s probably straight forward to make a javascript solution but would be nice to use Matrix if possible.


(Bart Banda) #11

Yea my bad…I forgot that my suggestion won’t work for this scenario… :frowning:

Yep, it’s pretty much the reason the frontend asset keyword was made.

%globals_X% keywords are all evaluated later in the processing of the page. So matrix will first evaluate all asset based keywords in the context of where they are printed, so for asset listing type format for example, it needs to do things like %asset_name% at the time it lists that asset, it will leave %globals_x till the end.

So when you do those types of condition checks, it will not do the checks properly because it’s basically checking if the evaluated keyword of %asset_assetid% matched the string %globals_asset_assetid%, not the evaluated keyword at that point.

The easiest other alternative I can think of is to pipe the asset listing through a REST asset where you can do some Server Side JS on the output of it and then print your menu that way?


(Charlotte Westney) #12

Hi Bart,

Thanks for that explanation and confirmation that its not just me getting my keyword replacements wrong!

Fundamentally for me, this example is another one that I’m having to ‘work around’ because menus are part of the design area and can’t be nested in.
This site isn’t that complex in terms of its grid code, but it has a few variations using quite different grid structures for the main page body, that will make putting that menu into the design and then having all the other grid code before and after it change for different customisations really tricky to implement. The only way I could do it would be to have pages with opening divs nested in, and then others with closing divs nested in, and that’s just really not good practice splitting up div code like that.

I need the functionality of a true menu area, but I also need the flexibility to not have to put that into a design file. A menu area that could be nested in, alongside all its wrapping divs, that would really be useful!

C.


(Bart Banda) #13

Can you explain a bit more about what you mean? So your issue is not really about setting a dynamic root node for the menu, it’s more about the formatting of each menu item?

Is this something you might still be able to do with keyword modifiers on the print tag value of each menu item?

Keen to understand the issue more so that we can maybe come up with an alternative solution.