Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Page Titles

Our old forums are still available as a read-only archive.

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

Page: 1 2 3
Go to End
Author Topic: 6415 Views
  • Bandit
    Avatar
    Community Member
    10 Posts

    Page Titles Link to this post

    There should be some area in the CMS where you can edit a default title "appendage". For example, if I'm building my site, I don't want the title of my page to be just "Home" - I might want it to be "Home | Bandit Website", and have that " | Bandit Website" appended to the end of every title within my site, rather than having to manually add it to each page.

    Thoughts?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Page Titles Link to this post

    I agree.

    Perhaps we have something in the _config.php like:

    global $siteTitle;
    $siteTitle = 'My cool site';

    Then, inside the code which generates <title></title> ($MetaTags) we include the global $siteTitle variable.

    That's just a rough guess on how we could do it. Sam, perhaps you have some thoughts on this?

    Cheers,
    Sean

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: Page Titles Link to this post

    My solution to this problem was to put it in the template.

    In head of Page.ss I have:
    [html]
    <title>$Title.XML - $SiteName</title>

    $MetaTags(false)

    [/html]

    and in _config.php I put

    $SiteName = "Nathan's Wondiferous Website";

    Passing 'false' to $MetaTags is supposed to exclude the title, so you can put it in yourself.
    Unfortunately, it seems to broken last I checked - you'll need to go into the MetaTags function in SiteTree and tell it to look for the strings 'true' and 'false' instead of booleans, since the template passes your false as a string.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Page Titles Link to this post

    How about actually removing the <title> generation from the $MetaTags function, so a site developer has control over the <title> attribute themselves, as well as being able to include $MetaTags for <meta></meta>.

    Thoughts?

    Cheers,
    Sean

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: Page Titles Link to this post

    Yeah, that makes alot more sense to me...not so good for backwards compatability of templates, though.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Page Titles Link to this post

    I've noticed this behaviour with template designers, especially when they don't assume $MetaTags generates the <title> element of the page... Your idea seems the best, since it's backwards compatible. So you have to check for 'false', rather than simply false?

    Cheers,
    Sean

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: Page Titles Link to this post

    I just changed the function to this:

    public function MetaTags($includeTitle = 'true') {
    $tags = "";
    if($includeTitle == 'true') {
    $tags .= "<title>" . Convert::raw2xml($this->MetaTitle ? $this->MetaTitle : $this->Title) . "</title>\n";
    }
    $tags .= "<meta name=\"generator\" http-equiv=\"generator\" content=\"SilverStripe 2.0 - http://www.silverstripe.com\" />\n";
          
    $charset = ContentNegotiator::get_encoding();
    $tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=$charset\" />\n";
    if($this->MetaKeywords) {
    $tags .= "<meta name=\"keywords\" http-equiv=\"keywords\" content=\"" . Convert::raw2att($this->MetaKeywords) . "\" />\n";
    }
    if($this->MetaDescription) {
    $tags .= "<meta name=\"description\" http-equiv=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n";
    }
    return $tags;
    }

    It's all in the first three lines - just treat $includeTitle as a string, and pre-set $tags to avoid errors. Although this way, you could do $MetaTags(oneonewasaracehorse) and it would work, too...

  • Andy
    Avatar
    230 Posts

    Re: Page Titles Link to this post

    I've changed the code to check for both boolean true and string 'true'. Thanks for this!

    6415 Views
Page: 1 2 3
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.