Forum

Thread tagged as: Problem

perch_page_attributes not showing

Hi,

I am having an issue where my perch_page_attributes are not displaying on a specific page. This is the page project.php file:

<?php

include($_SERVER['DOCUMENT_ROOT'].'/admin/runtime.php');

$project = perch_content_custom('Projects', [
  'page' => '/projects.php',
  'skip-template' => true,
  'filter' => 'slug',
  'match' => 'eq',
  'value' => perch_get('s'),
  'count' => 1
]);

$projectTitle = $project['0']['title'];

perch_page_attributes_extend([
  'pageTitle' => $projectTitle
]);

perch_layout('header');

perch_layout('contact-header');

perch_pages_navigation();

perch_content_custom('Projects', [
  'page' => '/projects.php',
  'template' => '_project-detail.html',
  'filter' => 'slug',
  'match' => 'eq',
  'value' => perch_get('s'),
  'count' => 1
]);

perch_layout('footer');

?>

This is the header.php layout file

<?php

$page = PerchSystem::get_page();

$page = str_replace('.php','', $page);
$pos = strrpos($page, '/');
$page = $pos === false ? $page : substr($page, $pos + 1);

$page_class = $page;

$current_page_url = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];

$domain = 'https://'.$_SERVER['HTTP_HOST'];

PerchSystem::set_var('page_url', $current_page_url);
PerchSystem::set_var('domain', $domain);

?>

<!doctype html>
<html class="no-js" lang="en">
    <head>

      <!-- Standard Head Elements -->

      <meta charset="utf-8">
      <meta http-equiv="x-ua-compatible" content="ie=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="/assets/css/styles.css">

      <title><?php perch_pages_title(); ?> | 24/7 Heating & Plumbing</title>

      <!--
      Favicons generated by https://realfavicongenerator.net
      -->

      <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
      <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
      <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
      <link rel="manifest" href="/site.webmanifest">
      <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#2e73aa">
      <meta name="msapplication-TileColor" content="#2e73aa">
      <meta name="theme-color" content="#ffffff">

      <!-- Twitter Card data -->

      <meta name="twitter:card" content="summary_large_image">

    <?php perch_page_attributes([ 'template' => 'default' ]);?>

    </head>
        <body class="<?php echo $page_class; ?>">

And this is the attributes default.html template:

<perch:if exists="description">
<meta name="description" content="<perch:pages id="description" label="Page Description" type="text" size="xl" count="chars" help="This is the page description, and must be below 200 characters. There is a count to the right for your reference" />">
<perch:else/>
<meta name="description" content="Are you looking for a qualified and experienced gas registered plumber in Cardiff or the surrounding South Wales area? Then look no further">
</perch:if>

<meta name="twitter:site" content="@">

<meta name="twitter:title" content="<perch:pages id="pageTitle"/> | 24/7 Heating & Plumbing">

<perch:if exists="description">
<meta name="twitter:description" content="<perch:pages id="description" label="Page Description" type="text" size="xl" count="chars" help="This is the page description, and must be below 200 characters. There is a count to the right for your reference" />">
<perch:else/>
<meta name="twitter:description" content="Are you looking for a qualified and experienced gas registered plumber in Cardiff or the surrounding South Wales area? Then look no further">
</perch:if>

<!-- Twitter images must be at least 280px wide by 150px tall, and under 1mb in size -->

<perch:if exists="twitter_image">
<meta name="twitter:image" content="<perch:pages id="domain" type="hidden"/><perch:pages id="twitter_image" type="image" label="Twitter Image" help="This should be at least 280px wide by 150px tall, and under 1mb in size. This is the image shown when the page is shared on Twitter. If not set it will default to the company logo"/>">
<perch:else />
<meta name="twitter:image" content="<perch:pages id="domain" type="hidden"/>/assets/img/twitter-image.jpg">
</perch:if>

<meta property="og:title" content="<perch:pages id="pageTitle"/> | 24/7 Heating & Plumbing" />
<meta property="og:url" content="https://<perch:pages id="page_url" type="hidden"/>" />
<!-- og:image should be at least 1200px x 630px, but under 5mb file size -->

<perch:if exists="facebook_image">
<meta property="og:image" content="<perch:pages id="domain" type="hidden"/><perch:pages id="facebook_image" type="image" label="Facebook Image" help="This should be at least 1200px wide by 630px tall, and under 5mb in size. This is the image shown when the page is shared on Facebook. If not set it will default to the company logo"/>" />
<perch:else />
<meta property="og:image" content="<perch:pages id="domain" type="hidden"/>/assets/img/facebook-image.jpg" />
</perch:if>

<perch:if exists="description">
<meta property="og:description" content="<perch:pages id="description" label="Page Description" type="text" size="xl" count="chars" help="This is the page description, and must be below 200 characters. There is a count to the right for your reference" />" />
<perch:else/>
<meta property="og:description" content="Are you looking for a qualified and experienced gas registered plumber in Cardiff or the surrounding South Wales area? Then look no further">
</perch:if>

<meta property="og:site_name" content="24/7 Heating & Plumbing" />

This page is set up as part of a two-page list-detail arrangement as shown here: Two page list and detail. I have the following in my .htaccess to make the url cleaner: RewriteRule ^project/([a-zA-Z0-9-/]+)$ /project?s=$1 [L]

On every other page the attributes are showing fine, but on this one they are missing from the rendered page - everything else is there. There is nothing in debug that looks out of the ordinary but I have included it below as well as diagnostics. If you could take a look and see where I might be going wrong that would be much appreciated

Many thanks

Mike

Diagnostics below:


Perch: 3.1, PHP: 5.6.31, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO Server OS: Darwin, apache2handler Installed apps: content (3.1), assets (3.1), categories (3.1), perch_forms (1.11) App runtimes: <?php $apps_list = [ 'perch_forms' ]; PERCH_LOGINPATH: /admin PERCH_PATH: /Users/mikeharrison/Google Drive/Client Work/247 Heating and Plumbing/Site/admin PERCH_CORE: /Users/mikeharrison/Google Drive/Client Work/247 Heating and Plumbing/Site/admin/core PERCH_RESFILEPATH: /Users/mikeharrison/Google Drive/Client Work/247 Heating and Plumbing/Site/admin/resources Image manipulation: GD PHP limits: Max upload 32M, Max POST 32M, Memory: 256M, Total max file upload: 32M F1: 3b606135b33e6a102526838f4152a807 Resource folder writeable: Yes HTTP_HOST: 247.loc DOCUMENT_ROOT: /Users/mikeharrison/Google Drive/Client Work/247 Heating and Plumbing/Site REQUEST_URI: /admin/core/settings/diagnostics/ SCRIPT_NAME: /admin/core/settings/diagnostics/index.php

Debug:

Debug Message - Perch 3.1
[1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch3_content_regions WHERE regionKey='Projects' AND (regionPage='/projects.php' OR regionPage='*')
[1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch3_content_index idx JOIN perch3_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch3_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=5 AND idx.itemRev=1)) AND ((idx.indexKey='slug' AND idx.indexValue='test-project')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval, regionID ORDER BY sortval ASC LIMIT 0, 1
[1] Using template: /templates/content/_project.html
Using sub-template: /templates/content/blocks/big_image.html
Using sub-template: /templates/content/blocks/big_text.html
Using sub-template: /templates/content/blocks/image_slideshow.html
Using sub-template: /templates/content/blocks/text_block_with_image.html
Using sub-template: /templates/content/blocks/text_block.html
Using sub-template: /templates/content/blocks/text_with_callout_text.html
Using sub-template: /templates/content/blocks/two_images.html
[3] SELECT catID, catPath FROM perch3_categories
[1] SELECT * FROM perch3_pages WHERE pagePath='/project.php' LIMIT 1
[4] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC
[0] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/project.php' LIMIT 1
[4] Using template: /templates/navigation/item.html
[1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch3_content_index idx JOIN perch3_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch3_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=5 AND idx.itemRev=1)) AND ((idx.indexKey='slug' AND idx.indexValue='test-project')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval, regionID ORDER BY sortval ASC LIMIT 0, 1
[1] Using template: /templates/content/_project-detail.html
[1] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/project.php' OR regionPage='*' ORDER BY regionPage DESC
Mike Harrison

Mike Harrison 37 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you use the non-rewritten URL, what happens?

No joy unfortunately, same result. Complete page renders just without the attributes

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's different about this page?

As far as I can tell, nothing. The only other thing I am doing on this page and no other is the perch_page_attributes_extend to add the project title to the page title. But removing this doesn't fix the issue. As comparison here is my projects.php list page, which shows the attributes successfully:

<?php

include($_SERVER['DOCUMENT_ROOT'].'/admin/runtime.php');

perch_layout('header');

perch_layout('contact-header');

perch_pages_navigation([
  'hide-extensions' => true
]);

perch_content_create('Projects', [
  'template'   => '_project.html',
  'multiple'    => true,
  'edit-mode' => 'listdetail',
]);

perch_content_custom('Projects', [
     'template' => '_project-listing.html',
]);

perch_layout('footer');

?>
Duncan Revell

Duncan Revell 78 points
Registered Developer

Mike,

your <?php perch_page_attributes([ 'template' => 'default' ]);?> doesn't have ".html" after the template name.

default.html might sort it out...?

UPDATE

Worked out the only other thing different about the project.php is it isn't visible in Perch admin, as it has no editable content areas. Added a perch_content('foo'); and reloaded the page, and when I did that the attributes appeared.

However the page won't ever have content that is directly editable on so I don't want it visible in the admin area really.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If there's no page, you can't have page attributes. You might be best to tell Perch that it's the listing page.

https://docs.grabaperch.com/perch/building/working-with-front-controllers/

Ah I see. Ok will go down that route - thanks for helping me unpick that one Drew!