Faloude Faloude - 14 days ago 6
PHP Question

SilverStripe retrieving MetaTags(param) on a DataObject as page

When using a DataObject as page, the

MetaTags(false|true)
loses its functionality. How can you make it work?

Controller action for retrieving DataObject

public function article(SS_HTTPRequest $request) {
$article = NewsArticle::get()->find("URL", $request->param('ID'));

if(!$article) {
return $this->httpError(404);
}

return array (
'Article' => $article,
'Title' => $article->Title,
'MetaDescription' => $article->MetaDescription
);
}

Answer

The MetaTags function is located in SilverStripes sitetree class.

Just copy it to your newsarticle dataobject and adjust it to fit your needs.

If you want to display more dataobjects than that one as a page, you should think about packing all the basic stuff like urlsegment, metatags, link ... in one class and than just extend this one.

There's also a module with does that DataObject-as-Page

Comments