21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 312 Views |
-
Page Titles

26 July 2011 at 10:06am
Hi,
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(Director::URLParam('Action')=='show'){
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...
-
Re: Page Titles

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!
-
Re: Page Titles

27 July 2011 at 3:12am
It depends on how your page title is set in the first place. In the original blackcandy Page.ss it uses the $MetaTitle property:
<title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> » $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...
-
Re: Page Titles

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...Cheers
| 312 Views | ||
|
Page:
1
|
Go to Top |

