XF 2.2 How to set root breadcrumb different for a specific navigation id?

bzcomputers

Well-known member
I have some custom pages under a specific navigation id. These pages produces their own breadcrumbs. The current board setting for "Root Breadcrumb" is Home which works everywhere on the site accept for these custom pages, where it currently causes duplicate entries.

If I set the "Root Breadcrumb" to None for the entire board the custom page breadcrumbs display as expected, unfortunately this causes issues everywhere else on the site.

How do I go about setting the "Root Breadcrumb" to None for a specific navigation id?

Or is there another way to go about zeroing out the default breadcrumbs on a custom page.
 
Hard to say what the issue is without seeing the code but a quick and easy fix would be to use a conditional statement utilising the nav ID.
 
Thanks for the feedback, I'm aiming at something like this...

Code:
<xf:if is="$data-page-section == '(custom pages nav id here)'">
    //set root breadcrumb = none
<xf:else />
    //set root breadcrumb = home
</xf:if>

I just can't seem to find the variable for the root breadcrumb.
 
The breadcrumbs are built from the $breadcrumbs var.

That var is an array which contains the data required to construct each element of the breadcrumbs.

For example:

1615767075506.webp

The root breadcrumb is determined by the option setting and the home page URL:

1615767362816.webp

However, if on a page which doesn't have a breadcrumb other than the root, the var is null.

I suspect you will want to modify this section of code (but it's difficult to say for sure without knowing exactly how your code works):

HTML:
<xf:macro name="breadcrumbs" arg-breadcrumbs="!" arg-navTree="!" arg-selectedNavEntry="{{ null }}" arg-variant="">
    <xf:if contentcheck="true">
        <ul class="p-breadcrumbs {{ $variant ? 'p-breadcrumbs--' . $variant : '' }}"
            itemscope itemtype="https://schema.org/BreadcrumbList">
        <xf:contentcheck>
            <xf:set var="$position" value="{{ 0 }}" />

            <xf:set var="$rootBreadcrumb" value="{$navTree.{$xf.options.rootBreadcrumb}}" />
            <xf:if is="$rootBreadcrumb AND $rootBreadcrumb.href != $xf.uri AND $rootBreadcrumb.href != $xf.fullUri">
                <xf:set var="$position" value="{{ $position + 1 }}" />
                <xf:macro name="crumb"
                    arg-position="{$position}"
                    arg-href="{$rootBreadcrumb.href}"
                    arg-value="{$rootBreadcrumb.title}" />
            </xf:if>

            <xf:if is="$selectedNavEntry AND $selectedNavEntry.href AND $selectedNavEntry.href != $xf.uri AND $selectedNavEntry.href != $xf.fullUri AND $selectedNavEntry.href != $rootBreadcrumb.href">
                <xf:set var="$position" value="{{ $position + 1 }}" />
                <xf:macro name="crumb"
                    arg-position="{$position}"
                    arg-href="{$selectedNavEntry.href}"
                    arg-value="{$selectedNavEntry.title}" />
            </xf:if>
            <xf:foreach loop="$breadcrumbs" value="$breadcrumb" if="$breadcrumb.href != $xf.uri AND $breadcrumb.href != $xf.fullUri">
                <xf:set var="$position" value="{{ $position + 1 }}" />
                <xf:macro name="crumb"
                    arg-position="{$position}"
                    arg-href="{$breadcrumb.href}"
                    arg-value="{$breadcrumb.value}" />
            </xf:foreach>

        </xf:contentcheck>
        </ul>
    </xf:if>
</xf:macro>
 
I was able to run a template modification find/replace for this section of the template to get the results I needed.

Code:
<xf:if is="$selectedNavEntry AND $selectedNavEntry.href AND $selectedNavEntry.href != $xf.uri AND $selectedNavEntry.href != $xf.fullUri AND $selectedNavEntry.href != $rootBreadcrumb.href">
                <xf:set var="$position" value="{{ $position + 1 }}" />
                <xf:macro name="crumb"
                    arg-position="{$position}"
                    arg-href="{$selectedNavEntry.href}"
                    arg-value="{$selectedNavEntry.title}" />
            </xf:if>

Thanks again @Brogan.
 
Top Bottom