Forum

Thread tagged as: Question

Setting a variable from Perch Navigation

Hi,

I am probably doing something stupid here but I can't get this to work. I am trying to set a variable from my navigation, to then use it inside a template (navigation is usually in a topbar, but in this instance is part of a large "hero" layout on the homepage).

I have this on my page:

$nav = perch_pages_navigation([],true);

PerchSystem::set_var('nav', $nav);

perch_content('Hero');

And in the template for Hero I have this:

<perch:content id="nav" />

However nothing is being output, and showall does not have the variable there so I assume it is not being created. How can I use my templated navigation inside another template?

If I echo $nav on the page I get the navigation as I would expect.

Thanks for any help

Mike

Diagnostics:

Perch Runway: 3.0.9, PHP: 5.6.30, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.0.9), assets (3.0.9), categories (3.0.9)
App runtimes: <?php $apps_list = [ ];
PERCH_LOGINPATH: /admin
PERCH_PATH: /Users/mikeharrison/Google Drive/Client Work/G H Davies/Site/admin
PERCH_CORE: /Users/mikeharrison/Google Drive/Client Work/G H Davies/Site/admin/core
PERCH_RESFILEPATH: /Users/mikeharrison/Google Drive/Client Work/G H Davies/Site/admin/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: ghd.dev
DOCUMENT_ROOT: /Users/mikeharrison/Google Drive/Client Work/G H Davies/Site
REQUEST_URI: /admin/core/settings/diagnostics/
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
Mike Harrison

Mike Harrison 37 points

  • 4 years ago

As is often the case, me hitting "Post" in the forum allowed me to solve it. I have done a couple of things in case anyone is interested:

1) Switched to perch_content_custom('Hero');

2) Changed the tag in the template to <perch:content id="nav" encode="false" />

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_content() caches the content when the region is edited, so runtime changes won't affect it.