Forum

Thread tagged as: Question, Problem

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>
Stephen Turvey

Stephen Turvey 0 points

  • 4 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

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:

<?php perch_content('Program overview'); ?>
<?php perch_content('Content'); ?>
<?php perch_layout('footer'); ?>
Simon Clay

Simon Clay 127 points

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.

Duncan Revell

Duncan Revell 78 points
Registered Developer

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:

perch_content_custom('page_title', perch_pages_title(true));

Instead of:

PerchSystem::set_var('page_title', perch_pages_title(true));

?

Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Stephen,

sorry for the confusion - you are setting the variable correctly, but instead of using:

perch_content('Program overview')

to get your content template onto the webpage, you will have to use:

perch_content_custom('Program overview', [])

instead.

Still confused, perhaps because Program overview is still being used as the example!

In my master template I have:

PerchSystem::set_var('page_title', perch_pages_title(true));

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:

<perch:content id="page_title" type="hidden" />

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!

Duncan Revell

Duncan Revell 78 points
Registered Developer

Where you have this in your master page:

<?php perch_content('Program overview'); ?>
 <?php perch_content('Content'); ?> 
<?php perch_layout('footer'); ?>

You need to use

<?php perch_content_custom('Program overview', []); ?>
etc 
etc

in order for the variable to be passed to the template.

Got it! Ok thank you.