Forum

Thread tagged as: Problem

Problem accessing page attributes

I'm trying to get a page attribute into a PHP variable on one of my page templates but I'm having a little trouble.

I have this in my master page

echo(perch_page_attribute('fromlevel',[],true));

Here is my attribute template (seo.html)

<meta name="description" content="<perch:pages id="description" label="Description" type="textarea" size="xs" escape="true" count="chars" order="10" />" />
<meta name="keywords" content="<perch:pages id="keywords" label="Keywords" type="textarea" size="xs" escape="true" help="Separate with commas" count="chars" order="20" />" />
<meta name="robots" content="<perch:pages id="noindex" label="Do not index" type="checkbox" value="noindex" append="," divider-before="Search engine indexing" order="40" /><perch:pages id="nofollow" label="Do not follow links" type="checkbox" value="nofollow" append="," order="50" /><perch:pages id="nosnippet" label="Do not show a snippet" type="checkbox" value="nosnippet" append="," order="60" />" />

<perch:pages type="number" id="fromlevel" label="Sub Navigation Level" suppress="true" help="Enter the on-page navigation level e.g. 0 for top level, 1 for second level, 2 for third level" order="30" />

I can output the description using the code below.

echo(perch_page_attribute('description',[],true));

Anything else is always blank. There are values set in page details for the page using this master.

Diagnostics below

Perch Runway: 2.8.30, PHP: 7.0.0, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 7e72f9690b1498a1bead7a637c33a831c0d2f655 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.30), assets (2.8.30), categories (2.8.30), perch_blog (5.0), perch_forms (1.8.3), perch_shop_orders (1.0.6), perch_shop_products (1.0.6), perch_shop (1.0.6), perch_members (1.5), perch_twitter (3.5.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_forms', 'perch_members', 'perch_shop', 'perch_twitter' );
PERCH_RESFILEPATH: .../Website/httpdev/httpdocs/assets/resources
PERCH_LOGINPATH: /perch
PERCH_PATH:.../Website/httpdev/httpdocs/perch
PERCH_CORE: .../Website/httpdev/httpdocs/perch/core
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: et:8888
DOCUMENT_ROOT: .../Website/httpdev/httpdocs
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Caleb Evans

Caleb Evans 1 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi Caleb, I think it's because you have suppress="true" in your template for the fromlevel.

Hi Simon

Thanks for the reply. I wondered that as well so I tried removing it but it made no difference. Description seems to be the only field I can output.

Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you templates structured? You've said this is included in a template called seo.html - is that included in the attribute template?

Hi Drew

Thanks for the response.

Yes, seo.html is included in the default attribute template using...

<perch:template path="pages/attributes/seo.html" />

I took the include out of the equation but still had no luck.

I then also removed suppress="true" and it is now coming through.

I'm not sure which combination was causing the problem but I'll have to use 2 separate templates, one for admin and one for the output.

Thanks for all your help.