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.

Archive /

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

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

Page Titles


Go to End
Reply


19 Posts   6565 Views

Avatar
Bandit

Community Member, 10 Posts

1 August 2007 at 11:09am

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?

Avatar
Sean

Forum Moderator, 922 Posts

1 August 2007 at 1:57pm

Edited: 01/08/2007 1:58pm

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

Avatar
Nathan Cox

Community Member, 99 Posts

1 August 2007 at 2:00pm

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.

Avatar
Sean

Forum Moderator, 922 Posts

1 August 2007 at 5:35pm

Edited: 01/08/2007 5:35pm

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

Avatar
Nathan Cox

Community Member, 99 Posts

1 August 2007 at 5:39pm

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

Avatar
Sean

Forum Moderator, 922 Posts

1 August 2007 at 5:48pm

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

Avatar
Nathan Cox

Community Member, 99 Posts

1 August 2007 at 6:01pm

Edited: 01/08/2007 6:02pm

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

Avatar
Andy

230 Posts

2 August 2007 at 9:40am

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

Go to Top