skip to Main Content

Is that possible to get nav’s handle or name from a Url inside that nav?

Let say i have a Url of a collection https://avasahome.myshopify.com/collections/ABC that is inside a ABC Test nav which the handle is abc-test.

Can i get abc-test from the Url https://avasahome.myshopify.com/collections/ABC?

Please help me with this cause i found no document about this matter.

Thank you!

2

Answers


  1. Put the below code in your liquid file. This is basically a function which invoked will return you the Nav Link Text

    get_nav = function(){
      var i, len, nav, ref;
    
      ref = $('.nav__link');
      for (i = 0, len = ref.length; i < len; i++) {
        nav = ref[i];
        if (nav.href === document.location.href) {
          alert(nav.text);
          //return nav.text;
        }
      }
    }
    
    Login or Signup to reply.
  2. This will assign your desired value as retrievedLinkHandle:

    {%- assign retrievedLinkHandle = false -%}
    {%- for link in nav.links -%}
      {%- if link.type == 'collection_link' and link.object.id == collection.id -%}
        {%- assign retrievedLinkHandle = link.title | handle -%}
        {%- break -%}
      {%- endif -%}  
    {%- endfor -%}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search