title: How to detect Silverstripe page is loaded in Controller as parent or child
body: <p>Our Silverstripe project has the following two page types:</p>
  
  <pre><code>class MultiSectionPage extends Page {
    private static $allowed_children = array(
      'Section'
    );
  
    public function PageSections() {
      $PageSections = Section::get()-&gt;filter(array('ParentID' =&gt; $this-&gt;ID));
      return $PageSections;
    }
  }
  
  class Section extends Page {
    public static $allowed_children = array();
    private static $show_in_sitetree = false;
  }
  </code></pre>
  
  <p>In the Layout/MultiSectionPage.ss template the following code loops through each child Section as a dataobject:</p>
  
  <pre><code>&lt;% loop $PageSections %&gt;
  &lt;% include MultiSectionPage_Section %&gt;
  &lt;% end_loop %&gt;
  </code></pre>
  
  <p>I want to make sure that if anyone accidentally links to a Section it redirects to the parent MultiSectionPage.</p>
  
  <pre><code>class Section extends Page {
    public function Link() {
      return parent::Link() . '#section-' . $this-&gt;ID;
    }
  }
  
  class Section_Controller extends Page_Controller {
  
    public function init(){
      parent::init();
  
      if(!$this-&gt;getResponse()-&gt;isFinished() &amp;&amp; $link = $this-&gt;Link()) {
          $this-&gt;redirect($link, 301);
          return;
      }
    }
  }
  </code></pre>
  
  <p>However using this method triggers a redirect even when viewing the MultiSectionPage as the init must get called each time the Section DataObject is rendered.</p>
  
  <p>How do I detect whether a Section Controller is being loaded as a standalone parent (redirect) or as child of a MultiSectionPage ?</p>