Jump to:

23376 Posts in 18176 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Page Titles

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

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

Page: 1
Go to End
Author Topic: 493 Views
  • Futureweb
    Avatar
    Community Member
    232 Posts

    Page Titles Link to this post

    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...

  • Futureweb
    Avatar
    Community Member
    232 Posts

    Re: Page Titles Link to this post

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

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Page Titles Link to this post

    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 %> &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...

  • Futureweb
    Avatar
    Community Member
    232 Posts

    Re: Page Titles Link to this post

    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

    493 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.