2016-07-06 23 views
2

このようなサイト構造/メニューレイアウトを想像してみてすべてのメニュー項目は、独自のURLと内容で実際のページにリンクします。しかし、太字の項目はリンク、コンテンツ、URLのない単なるメニュー項目であり、ホバー上のサブメニューを折り畳むことが唯一の目的です。 SilverStripeでは、このようなページエンティティをすぐに作成することはできません。私は(後者はあるかもしれない単にURLスラグなしにもメニュー項目、コンテンツのないよう、最高のケースで機能するダミーページを作成するには、クリーン、最もシンプルかつ少なくともハック方法を探していSilverStripeダミーページ/メニュー項目

難しい)。

答えて

3

RedirectorPageを作成してリダイレクト先として最初のサブページを選択するだけで、追加コードなしで「ダミー」ページを作成できます。

個人的には、私が以前に訪れた場合、最初の子ページに自動的にリダイレクトする、より単純な "RedirectorPage"のバージョンを使用しました。

例:SEOの目的のために最も可能性の高い優れている私は、など、あなたのURLは、その後services/peeling-potatoesになりますので、URLスラグは、実際に有益だと思う

class ChildRedirectorPage extends Page 
{ 
    private static $description = 'Page that has no content but automatically redirects to the first of its child-pages'; 

    public function ContentSource() { 
     if($firstChild = $this->Children()->First()) { 
      return $firstChild; 
     } else { 
      return $this; 
     }  
    } 

    public function Link($action = null) { 
     // prevent link "redirection" when we're in CMS 
     if (!is_subclass_of(Controller::curr(),'LeftAndMain')){ 
      if($firstChild = $this->Children()->First()) return $firstChild->Link($action); 
      else return parent::Link($action); 
     } 
    } 

    public function getCMSFields() { 
     $fields = parent::getCMSFields(); 
     $fields->removeByName('Content', true); 
     return $fields; 
    } 
} 

class ChildRedirectorPage_Controller extends Page_Controller 
{ 
    function init() { 
     parent::init(); 
     if($firstChild = $this->Children()->First()) { 
      $this->redirect($firstChild->Link(), 301); 
     }   
    } 
}