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.

Template Questions

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


Reply

5 Posts   1033 Views

Avatar
baba-papa

20 September 2010 at 1:27am Community Member, 279 Posts

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

20 September 2010 at 2:56am Community Member, 271 Posts

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

20 September 2010 at 2:57am Community Member, 279 Posts

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

Avatar
TotalNet

20 September 2010 at 10:40am (Last edited: 20 September 2010 10:50am), Community Member, 181 Posts

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

20 September 2010 at 7:23pm Community Member, 279 Posts

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.