Forum

Thread tagged as: Question

Accessing page attributes in navigation templates

In previous versions of perch, I've been able to add a page attribute to a page and then access that attribute in navigation templates like so:

<perch:pages id="page_intro" />

... with page_intro being the attribute in question...

I can't seem to do that in the latest version. If I use <perch:showall />, the attributes are there, but as an object in pageAttributes, i.e.

pageAttributes  {"page_intro":{"_flang":"html","raw":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed{...}

How can I get access to that value in navigation templates? Is there a way to access object values?

Something like this would be handy ;-)

<perch:pages id="pageAttributes.page_intro.raw" />
Jon Young

Jon Young 0 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:pages id="page_intro"> would be correct if you add the missing type attribute.

Thanks for your reply - it was because I copied and pasted the nav snippet from a previous site I had built which used 'use-attributes' => false. So, my bad...

perch_pages_navigation([
    'hide-extensions'   => true,
    'template'          => ['main-nav.html', 'main-nav-subitems.html'],
    'use-attributes'    => false
]);

For your info, <perch:pages id="page_intro"> works just fine without the type attribute.

Sorry to have taken your time!