CMS Development

peesen
Contributor

HubL Tag for Navigation-Label (Text)

SOLVE

Hi!

 

Is there a way to show the name i gave the page in the main-navigation on the page with a hubl-tag?

 

The text i want to show:

navigation.jpg

 

Thank you so much for your help

Pascal

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

HubL Tag for Navigation-Label (Text)

SOLVE

Hey @peesen 

 

I see what you're doing now.

Try something like this:

{% set node = menu(*menuId*) %}
{% for child in node.children %} {# loop through the menu #}
  {% if child.activeNode == true %} {# test if the current menu child is active #}
    {% set active_node = child.label %} {# declare a variable that we can use and test against later #}
  {% endif %}
{% endfor %} {{ active_node }} {# display the label #}

 

Unfortunately I am unable to test this, so I hope its straight forward enough!

 

View solution in original post

6 Replies 6
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

HubL Tag for Navigation-Label (Text)

SOLVE

Hey @peesen 

 

Check out this solution here!

 

Expanding on this you can get the individual label by using something like this:

{{ menu(*your menus id*).children[0].label }}

This will get the first (becasue they're 0 based numbering) menu item's label!

0 Upvotes
peesen
Contributor

HubL Tag for Navigation-Label (Text)

SOLVE

Hey Kevin, thank you so much for your help.

 

When i use your code, i always get the first menu item, is this correct? I always need the navigation "label" of the active menu item. Is this even possible?

 

Thank you so much for your help and best regards.

Pascal

 

@hubspotWould be glad for some help 🙂

0 Upvotes
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

HubL Tag for Navigation-Label (Text)

SOLVE

Hey @peesen 

 

I see what you're doing now.

Try something like this:

{% set node = menu(*menuId*) %}
{% for child in node.children %} {# loop through the menu #}
  {% if child.activeNode == true %} {# test if the current menu child is active #}
    {% set active_node = child.label %} {# declare a variable that we can use and test against later #}
  {% endif %}
{% endfor %} {{ active_node }} {# display the label #}

 

Unfortunately I am unable to test this, so I hope its straight forward enough!

 

peesen
Contributor

HubL Tag for Navigation-Label (Text)

SOLVE

Hey Kevin, your solution did not work in my case. Did you check this in one of your projects?

0 Upvotes
peesen
Contributor

HubL Tag for Navigation-Label (Text)

SOLVE

This is not working in my case. I wrote an answer last week about it. Can maybe Hubspot get into this? I would love to get this done soon.

 

Thank you so much and best regards

Pascal

0 Upvotes
peesen
Contributor

HubL Tag for Navigation-Label (Text)

SOLVE

Hey @Kevin-C 

 

I added the menu ID and tried to use your script the following:

{% set node = menu(32047489403) %}
{% for child in node.children %} {# loop through the menu #}
  <span>Found nodes</span>
  {% if child.activeNode == true %} {# test if the current menu child is active #}
    <span>Found active node</span>
    {% set active_node = child.label %} {# declare a variable that we can use and test against later #}
  {% endif %}
{% endfor %}
		
{{ active_node }} {# display the label #}

 

The message "found nodes" i get on almost every page. Its strange that the number of nodes is not always the same. The message "found active node" i just get on some pages which looks randomy but i could never get the the output of the "active_node" label.

 

Thank you so much for your help so far. If you have any idea what could be wrong, i would be glad. Im maybe looking into another solution with a a text-field for every page where the name of the page has to be inserted manually again and i get the value from there.

 

Have a nice day and best regards

Pascal

0 Upvotes