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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Global Meta-data


Go to End


5 Posts   2757 Views

Avatar
NickJacobs

Community Member, 148 Posts

24 February 2009 at 2:10pm

Hi Is there a way of specifying default meta-tags in the CMS. A lot of my small client sites just don't use the meta-fields on each page, so being able to set a default (which can be overridden) would be great.

Avatar
Carbon Crayon

Community Member, 598 Posts

25 February 2009 at 4:15am

Hi Tsunami

this page might be of help: http://doc.silverstripe.org/doku.php?id=recipes:adding_metatags

Do you want your clients to be able to change them or are you just going to set them yourself, in which case you can use the above method or simply just put them in the Page.ss template?

Avatar
NickJacobs

Community Member, 148 Posts

25 February 2009 at 9:12am

That's a good start thanks aram...

Ideally what I would like to do is set global meta-data for the site in the page template, but then add any page specific keywords (from the cms) to the global tag. Is there any way to reference individual meta fields, something like this in the template.ss:

<meta name="Keywords" content="beach accommodation luxury $MetaKeywords" />

Is there a document that tells me all of the CMS tags I can reference in my templates??

Cheers

Avatar
Carbon Crayon

Community Member, 598 Posts

25 February 2009 at 10:06am

I think you can actually do exactly that!

Have a look at sapphire/core/model/sitetree (which is the class that Page extends). In its $db array it has:

MetaKeywords
MetaDescription
MetaTitle
ExtraMeta

so you should be able to use those variables in your template just as you describe :)

Avatar
neilcreagh

Community Member, 136 Posts

17 July 2009 at 12:33am

Hi Guys,

I've added default global Meta Tags by using the Homepage Meta Tags as the default set, then only replacing them if individual meta tags are actually specified for that page. So, if most pages have no meta tags set tehn the homepage set will be used as default but if one of the pages has a different title, or description or keywords it will use them.

You can have the correct page title appear in the default set on each individual page. So, if a page has left any Meta tags blank it actually uses the default set (homepage tags) PLUS the actual page title. eg. About Us ›› The ABC Company Website

To do this you need to add a simple function to your Page_Controller in Page.php:
function GetHomePage(){
return DataObject::get("HomePage");
}

Then, on the main Page.ss template call your Meta Tags like so:

<title><% if MetaTitle %>$MetaTitle<% else %>$Title &raquo; <% control GetHomePage %>$MetaTitle<% end_control %><% end_if %> </title>

<meta name="title" content="<% if MetaTitle %>$MetaTitle<% else %>$Title &raquo; <% control GetHomePage %>$MetaTitle<% end_control %><% end_if %>" />

<meta name="description" http-equiv="description" content="<% if MetaDescription %>$MetaDescription<% else %>$Title <% control GetHomePage %>$MetaDescription<% end_control %><% end_if %>" />

<meta name="keywords" http-equiv="keywords" content="<% if MetaKeywords %>$MetaKeywords<% else %>$Title <% control GetHomePage %>$MetaKeywords<% end_control %><% end_if %>" />

Hope this helps!

ps. By default Silverstripe populates the MetaTitle with the page title, so I've included the Default Title from the Homepage after it.