invictus
invictus

Reputation: 825

Silverstripe 3 - LinkingMode() for Dataobject

I created this function to show dataobjects as page

// DISPLAY ITEM AS PAGE
public function produkt(SS_HTTPRequest $request) {
    $urlSegment = $this->request->param('URLSegment');
    $item = ShopItem::get()->filter('URLSegment', $urlSegment)->first();

    if( $item ) {
        $data = array(
            'Item' => $item,
            'Title' => $item->Title,
            'Parent' => Shop::get()->First(),
            'Controller' => $this,
            'URLSegment' => $item->URLSegment
        );
        return $this->customise($data)->renderWith(array('ShopItem', 'Page'));
    } else {
        return $this->httpError(404);
    }
}

That's my YML File

---
Name: productRoute
After: 'framework/routes#coreroutes'
---
Director:
  rules:
    'onlineshop//produkt/$URLSegment!': 'Shop_Controller'

The function is on my Shop_Controller. and the Dataobjects are shown under onlineshop/produkt/blablabla-1

That works fine but in the navigation the link "Onlineshop" is not highlight as section.

I think I need to put the "LinkinMode()" function in my dataobject. But I don't know what the function should contain. return section current or link doesen't work.

Can someone help me?

thank you in advance

Upvotes: 0

Views: 367

Answers (1)

gherkins
gherkins

Reputation: 14983

You just want to highlight "Onlineshop" which is a Page in your SiteTree, right?

If so, just override the LinkingMode() method inside that Class (extending SiteTree) and make it return section or current for your custom route being active...

You would just need that method on the DataObject itself if you would like to show each DataObject in the Navigation and highlighted when active.

see http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/

Upvotes: 1

Related Questions