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.

Template Questions /

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

MetaTags are missing after changing URL interpretation by Director::addRules


Go to End


5 Posts   1939 Views

Avatar
baba-papa

Community Member, 279 Posts

20 September 2010 at 1:27am

One of my page types doesn´t show the meta data (keywords, description) in the frontend after I customized the URL interprtation:

Director::addRules(100, array(
    'view/$ID/$Name' => 'SomePage_Controller'
));

Is this a bug? What can I do about it? As soon as I remove this rule, the meta keywords etc will show in the xhtml code.

Avatar
Martijn

Community Member, 271 Posts

20 September 2010 at 2:56am

MetaTags are part of SiteTree. So if you don't have a SiteTree (or subclass), the method is not available.

Does SomePage_Controller return a Page somewhere?

Avatar
baba-papa

Community Member, 279 Posts

20 September 2010 at 2:57am

Yes it does, it´s a child of Page.

Avatar
TotalNet

Community Member, 181 Posts

20 September 2010 at 10:40am

Edited: 20/09/2010 10:50am

Presumably, you are returning a DataObject through that page.

add the following to your DataObject class

function MetaTags($includeTitle){
return SiteTree::MetaTags($includeTitle);
}

Because you are accessing the controller directly, there is no Page object associated with the request and therefore no existing Meta Tags to use. The above code will allow you to return the Meta Tag values you have assigned to your DataObject through your view function.

Avatar
baba-papa

Community Member, 279 Posts

20 September 2010 at 7:23pm

I am showing a DataObject on that page by urlParams['ID']. I tried SiteTree::MetaTags() as a return value but it didn´t work. MetaTags in not a static function.
Thanks for Your hint anyways. I implemented a function MetaTags() in the SomePage_Controller and now it works. This isn´t a clean solution i suppose.