Forum
Page title in template only appears after saving in admin
I have a page template that looks like this:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/admin/runtime.php');
PerchSystem::set_var('page_title', perch_pages_title(true));
perch_content_create('Page header', array(
'template' => 'page_header.html',
'multiple' => false,
));
perch_content_create('Content', array(
'template' => 'programs/freeform.html',
'multiple' => true,
));
perch_layout('header', array(
'title' => perch_pages_title(true),
));
?>
<?php perch_content_custom('Page header'); ?>
<?php perch_content('Content'); ?>
<?php perch_layout('footer'); ?>
The Page header content template is this:
<div class="clear feature-block">
<div class="wrap wrap--large">
<h1><perch:content id="page_title" type="hidden" /></h1>
<perch:if exists="sub-heading"><p class="sub-heading"><perch:content id="sub-heading" type="text" label="Sub heading" help="Optional" /></p></perch:if>
</div>
</div>
When I create a new page using this template the h1 doesn't appear unless I go in to the 'Page header' content region in the admin and click "Save changes".
Please can you let me know where I'm going wrong? Thanks.
What would you expect it to be before you've entered it?
I'm not trying to enter it manually I want it to automatically pull in the perch_pages_title
There isn't a title until you've added on though. I'm completely confused.
The page title is created when you "Add page" in the admin. That's the title I want to pull in automatically to all new pages created using a certain page template.
I can't use <?php perch_pages_title(); ?> because it's inside a content template so instead I'm trying:
Along with:
(as seen in markup pasted originally)
Hi Simon. I can't see where I'm passing in "title"? Other than to the header layout template which is a separate thing.
Hi Stephen, you are right. I deleted my comment actually, because I was wrongly referring to the layout template.
The
perch_content_custom('Page header');
won't have any template content saved until the Region is saved for the first time.That is what is happening. So that's normal behaviour then?
In this case the only other part of the region is an optional field (subheading) so there's not always a reason for anyone to go in and save that region.
Yes it is. I've just ran a test and that is the case.
I think the best alternative is to move the H1 and divs out of the template and output the page title in the page. Something like this:
Yes, I thought as much myself.
Thanks for your help.