Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Page Titles

Go to End

4 Posts   956 Views


Community Member, 244 Posts

26 July 2011 at 10:06am


I've got a page type called 'products' and within this, i'm showing load of products. At the moment, each of these products are just using the same page title the main page

in the page controller I have something like:

if($ID= Director::URLParam('ID')){
$filter = "`urlName` = '".$ID."'";
return DataObject::get('Product', $filter);

and what I want is the html page title to be like : {Product Name}, {Product Category}, {My Site Name}

but I've really no idea where I can define the title so it comes back into the html title tag...


Community Member, 244 Posts

26 July 2011 at 10:07am

in fact, i need my page title to show almost exactly the same the page title on this page!


Forum Moderator, 1391 Posts

27 July 2011 at 3:12am

It depends on how your page title is set in the first place. In the original blackcandy it uses the $MetaTitle property:

<title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; $SiteConfig.Title</title>

So you could change that. The thing is: you need to prepare it before the template is parsed, and in order to do that you need to know the product details in advance. One way to do that is use the init() method. Simplified and not tested:

function init() {
	if ($product = getProduct()) {
		$this->MetaTitle = $product->Title; // or what you want it to be

function getProduct() {
	return DataObject::get_by_id('Product', $ID);

Note: you could store the product in a variable so you don't have to do the query twice...


Community Member, 244 Posts

27 July 2011 at 8:05am

Hi martimiz,

That makes sense, I had tried setting the meta title - but now i see it needs setting before the title part is written out to the page.
I'll give that a go - it'll help a lot with my page SEO to get the product titles into the pages...