Navigation Parsley Variable Output



Using the {{ navigation }} Parsley variable appears to generate a structure list of the sitemap. Inspecting the HREF values used for each link in this list shows that they utilize relative paths. Is it possible to switch the output to instead use absolute HREF URLs?

Reason for this (as I understand from SEO), is that when a crawler views a relative URL it will attempt to crawl it multiple times (due to the different combinations that exist for http/https and www/non-www) as opposed to just crawling it once if an absolute URL is used (since protocol and www/non-www is specified).

If it is not possible to direct the {{navigation}} Parsley variable to switch between outputting absolute and relative paths, is there a workaround you would recommend?


Currently there is no setting for changing the navigation call to use absolute URLs. The main reasons for this are, the redirects for http(s), trailing slashes and www settings are created automatically for all pages, and this site is served in multiple stage environments with different root domains. Since the crawlers don’t have to check multiple versions of the root domain, there isn’t additional crawl cost added.

Yes, the “hidden” vs “live” setting is was dictates whether a page shows up in both the navigation call and the sectionlinks call. Additionally if a page with child pages is set to hidden, the child pages will also not be called in the navigation or sectionslink but can be independently set to hidden or live.

If you want to create a custom navigation style list of pages, the best way is through a dataset. Here you can have fields for what displays as the link, where the link clicks to, parenting of links, and any other features or attributes you want to assign. Then you can fully customize how that is called and displayed. This way you can bypass both the hidden/live settings and the relative URL output inherit in the navigation call.

Below is example code from a dataset navigation I’ve written. It may take a moment to grok and may have more or less functionality than you need but can hopefully give you a starting point for your own if you need to write that.

{{ each navigation as nav where nav.parent_link < 1 sort by nav.sort_order }}
         {{ if {nav.external_link} }}
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-{{ nav.zid }}"><a href="{{ nav.external_link }}" onclick="__gaTracker('send', 'event', 'outbound-widget', '{{ nav.external_link }}', '{{ nav.nav_item }}');" target="_blank"><span>{{ nav.nav_item }}</span></a></li>
         {{ else }}
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-{{ nav.zid }}"><a href="{{ truepath({nav.internal_link}) }}" ><span>{{ nav.nav_item }}</span></a>
          <ul class="menu">
           {{ each navigation as subnav where subnav.parent_link = {nav.zid} sort by subnav.sort_order }}
           {{ if {subnav.external_link} }}
           <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-{{ subnav.zid }}">
            <a href="{{ subnav.external_link }}" target="_blank" onclick="__gaTracker('send', 'event', 'outbound-widget', '{{ subnav.external_link }}', '{{ subnav.nav_item }}');">
             <span>{{ subnav.nav_item }}</span>
           {{ else }}
           <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-{{ nav.zid }}">
            <a {{ if {subnav.additioanl_hash} }}href="{{ truepath({subnav.internal_link}) }}#{{ subnav.additioanl_hash }}" class="ascroll"{{else}}href="{{ truepath({subnav.internal_link}) }}"{{ end-if }}><span>{{ subnav.nav_item }}</span></a>
           {{ end-if }}
           {{ end-each }}
         {{ end-if }}

You can see I loop through the parent links first and then loop through the subpage links. A couple other things to note, the “internal link” field assigns the zid of the page, so to get the corresponding URL you can use {{ truepath(~zid~) }}.

Let me know if this helps, or drums up more questions.