Thread tagged as: Question, Problem, Field-Types

Page title id in a perch .html template

Hi, is there a way to pull in the page title in a perch template like so:

<perch:content id="pageTitle" />

Im using perch_content_custom to pull in a template for each file under a directory like so:

  <?php perch_content_custom('Case Study Banner', array(
  )); ?>

And in that template im trying to just display the title of the page that is being pulled in but i cant find any documentation for this?

I know there is the php version but this wont work in a content template, or would it be better to set the title as an editable field in perch so you can manually add it and pull it through?


ewe agency

ewe agency 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

See this information about passing variables into templates:

Okay ive done that but its outputting the parent directory page title not the sub-page title name:

Perch_content_custom with vars set:

    $pagetitle = perch_pages_title(true);

      'title' => $pagetitle,

    perch_content_custom('Case Study Banner', array(


Perch content var being pulled in case_study_list.html:

<perch:content id="title" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

It should be outputting the value returned by perch_pages_title(true)

Yeah thats what its outputting which is the parent page /case-studies/index.php but im trying to output the page title of /case-studies/foo.php

The perch_content_custom is on the index.php page so the perch_pages_title is outputting that but i thought running it through a variable would output whats on the sub-pages. Unless i need to include the variable on the sub-page template?

Duncan Revell

Duncan Revell 78 points
Registered Developer

I think you might have to get complicated with an each filter - I'm not sure what data would be returned when getting regions from multiple pages, so start by getting the raw data:

$raw_data = perch_content_custom('Case Study Banner', 
array( 'page'=>'/case-studies/*', 

See if you can work out what is returned for each page (probably an array) - if there is some sort of id for each page returned (it might be _pageID), you can use an each filter:

perch_content_custom('Case Study Banner', 
array( 'page'=>'/case-studies/*', 
'each'=>function($item) {
$item['title'] = perch_page_attribute('pageTitle', ['_id' => $item['_pageID']], true);
return $item;

This is getting the data for each page, passing it into the function as $item, getting the pageID of each item and then calling the pageTitle attribute for that page and finally passing it into an id of title for each item. Your template will process the id='title' for each page.

In theory...

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Enabling debug would help you here:

As we haven't seen your Diagnostic Report I don't know if this is Perch or Runway but if it is Runway you don't need the output_debug line.

Ahh okay i understand what i was doing wrong now, Thanks for the help!