Trouble outputting custom attribute in autonav template

Permalink
I need to separate page titles from titles that appear in navigation and page lists so have created a new page attribute called nav_title.

I'm trying to output this in a breadcrumbs autonav template like this:

<nav class="crumbs crumbs-top">
  <ul>
  <? foreach($navItems as $ni) : ?>
    <? if($ni->isCurrent) : ?>
    <li class="current <?= $ni->classes ?>">/
      <? if ($c->getAttribute('nav_title')) : ?>
      <a href="<?= $ni->url ?>"><?= $c->getCollectionAttributeValue('nav_title') ?></a>
      <? else : ?>
      <a href="<?= $ni->url ?>"><?= $ni->name ?></a>
      <? endif ?>
    </li>
    <? elseif(($ni->isCurrent = !0) && ($ni->isEnabled)) : ?>
    <li class="<?= $ni->classes ?>">/
      <? if ($c->getAttribute('nav_title')) : ?>
      <a href="<?= $ni->url ?>"><?= $c->getCollectionAttributeValue('nav_title') ?></a>


The issue is that the code outputs the nav_title for the current page across all pages in the trial like this (Product Name is the page being viewed):

/ Product Name / Product Name / Product Name / Product Name

Where as the trail should look like this:

/ Home / Shop / Sheets / Product Name

The links all go to the right places - it's just the nav_title attribute that's affected.

Can anyone see what I'm doing wrong? BTW, I'm using Jordan's clean autonav block template incase that makes a difference.

Cheers

Ben

 
cmscss replied on at Permalink Reply
Actually, have just discovered that the issue only appears on the product page type - on other page types it seems to be working.
cmscss replied on at Permalink Reply
Can't quite figure this out as the page-types are all pretty similar - here's the product.php page_type:

<?php
  defined('C5_EXECUTE') or die("Access Denied.");
  $ih = Loader::helper('image'); // load image helper
  // Prepare main_image thumb for snipcart cart buttons
  $mainImageThumb = $c->getAttribute('main_image');
    if ($mainImageThumb) {
      $cartThumb = $ih->getThumbnail($mainImageThumb, 50, 50, FALSE); // ($img, width, height, TRUE/FALSE for cropping)http://www.concrete5.org/api/Concrete5_Helper_Image.html... - using 9999 effectively means 'no maximum size'
    }
  // thumb is output as data attribute on .l-main - then jquery inside theme.js places the thumb into cart buttons
?>
<? $this->inc('elements/html_header.php'); ?>
<? $this->inc('elements/breadcrumbs.php'); ?>
  <div id="l-content">
    <? $a = new Area('Title'); if($a->getTotalBlocksInArea($c) > 0 || $c->isEditMode()): ?>
    <div class="l-title">
cmscss replied on at Permalink Reply
OK, it doesn't seem to be the page type as changing the page type didn't fix the issue.

Is it possible that it's something to do with the nesting in the output of the trail somehow? Sorry, our php is pretty basic.
cmscss replied on at Permalink Best Answer Reply
OK, $c grabs the current page object and applies it to each item in the trail - hence the current page repeating down the trail.

For my own reference (and others struggling with this) we needed to use the navigation helper to pull the attribute instead ($ni is a variable set at the top of the template and grabs the c5 navigation helper):
$ni->cObj->getAttribute('nav_title')

So the full updated breadcrumb template works like this:
<nav class="crumbs crumbs-top">
  <ul>
  <? foreach ($navItems as $ni) : ?>
    <? if (($ni->isCurrent) && ($ni->isEnabled)) : ?>
    <li class="current <?= $ni->classes ?>">/
      <? if ($ni->cObj->getAttribute('nav_title')) : ?>
      <a href="<?= $ni->url ?>"><?= $ni->cObj->getAttribute('nav_title') ?></a>
      <? else : ?>
      <a href="<?= $ni->url ?>"><?= $ni->name ?></a>
      <? endif ?>
    </li>
    <? elseif (($ni->isCurrent = !0) && ($ni->isEnabled)) : ?>
    <li class="<?= $ni->classes ?>">/
      <? if ($ni->cObj->getAttribute('nav_title')) : ?>
      <a href="<?= $ni->url ?>"><?= $ni->cObj->getAttribute('nav_title') ?></a>