Forum
How to populate page title tag in a layout file from content in a template file?
Hi
I'm currently finishing off an estate agents website and was looking to include some of the content from the content template into the title tag in the layout page.
So for example the title tag will read...
<title>3 Bedroom House For Sale in Norwich only £199,995</title>
..with "3" "Norwich" and "199,995" coming from the content.
I currently have the following all up and running which I've taken from https://solutions.grabaperch.com/architecture/layout-variables
$title = perch_content(perch_get('s'), 'bedrooms', true) . ' Bedroom Property For Sale in xxxx only £xxx';
perch_layout ('forsale.head', array(
'title'=>$title
));
...but the number of bedrooms isn't displaying.
Any help would be gratefully received.
Glen
The issue is here:
The first argument to
perch_content()
is the region name. The second is an array of options for displaying that region.I'm not clear what the arguments you're specifying are intended to do.
Hi Drew
Thanks for the speedy reply. Updated code...
'Property Details' is the region
'bedrooms' is the ID of the content (which is a small text box which include a number eg 4)
perch_get()
is for reading parameters from the GET request - i.e. from the query string on the URL. You don't need that here.To get a specific item from the region, you need to use
skip-template
withperch_content_custom()
;Drew - you're a superstar!
How can I format the number in the price? It's currently outputting as 295000 when it needs to be 295,000
format="#:0"
is in the content template if that's any help?Glen
You can use
number_format()
: