Forum
perch_pages_title in a template
I'm having trouble with the same sort of thing, trying to use the perch_pages_title in a template. Nothing is getting output between the <h1></h1> tag. Please can you tell me where I'm going wrong?
Master Page:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/admin/runtime.php');
PerchSystem::set_var('page_title', perch_pages_title(true));
perch_content_create('Program overview', array(
'template' => 'programs/program_overview.html',
'multiple' => false,
));
perch_content_create('Content', array(
'template' => 'programs/freeform.html',
'multiple' => true,
));
perch_layout('header');
?>
And template:
<div class="program-image clear">
<h1><perch:content id="page_title" type="hidden" /></h1>
<p class="program-image__description"><perch:content id="overview-description" type="text" label="Short description" required="true" /></p>
</div>
Is that all of your master page?
perch_content_create will create a region, but not output anything to the browser.
You'll need to call
perch_content('Program overview')
somewhere on your page to get the template output.No it's not all of it, just the important parts I thought. FYI the rest goes like:
You'll need to use perch_content_custom to use the variable I think.
Not according to Drew's response for the same query here:
https://forum.grabaperch.com/forum/04-10-2015-perch-pages-title-in-a-template
In that case the person's issue was resolved but I can't seem to get the same to work for me. Also, please ignore my own messages at the end of that topic which I think went unnoticed because it's an old post.
Thank you.
I agree with Simon - you'll need to use
perch_content_custom('Program overview', [])
in order to be able to use the variable.It's something to do with perch_content using cached content and perch_content_custom generating the content on the fly, which is what you'll need to pass variables around. I think.
It's perch_pages_title I'm trying to use in a template - the 'Program overview' was Duncan picking up on what he thought might be another problem because I hadn't pasted all of my template.
But are you saying I should use:
Instead of:
?
Hi Stephen,
sorry for the confusion - you are setting the variable correctly, but instead of using:
to get your content template onto the webpage, you will have to use:
instead.
Still confused, perhaps because Program overview is still being used as the example!
In my master template I have:
So I think you are saying that the variable is being set correctly there?
Then, in my content template I am currently using this to try and show it:
So what I don't understand is why you have said "instead of using perch_content..." because actually I'm using perch:content...
Thanks for help so far!
Where you have this in your master page:
You need to use
in order for the variable to be passed to the template.
Got it! Ok thank you.