Forum

Thread tagged as: Question

Page Title in Template

Is there a simple way to display the title of the page in a template(html) file?

Tony Astley

Tony Astley 0 points

  • 4 years ago

We put most of the html in templates/pages/ templates and page titles usually in templates/layout/global.header.php as

<title><?php perch_pages_title(); ?></title>

Can we use it in a content html template?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You could pass it in as a template variable although you would then need to use perch_content_custom to display the template. We'd need info as to what you are trying to do to help further.

I'm creating a gallery region for the user to upload images. What I'm trying to do is use the page title of the page as a fallback for the "alt". For instance:

<img src="<perch:content type="image" id="galleryImage" width="960" />" alt="<perch:if exists="imageName"><perch:content id="imageName" type="text" label="Image Name" /><perch:else /><perch:pages id="pageNavText" /></perch:if>" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

So yes, the best approach is to pass it into the template from the page.