Forum
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(
'page'=>'/case-studies/*',
'template'=>'case_study_list.html',
)); ?>
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?
Cheers!
See this information about passing variables into templates: https://docs.grabaperch.com/templates/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:
Perch content var being pulled in case_study_list.html:
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?
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: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 aneach
filter: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 theid='title'
for each page.In theory...
Enabling debug would help you here: https://docs.grabaperch.com/perch/configuration/debug/
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!