title: Using Plates in PHP
body: <p>I'm new to using Plates template library for PHP. I have a few questions about how to use it.</p>
  
  <p>I'm looking through the docs I don't see a way to set a global layout. Is there not a way to do that?</p>
  
  <p>I'm using it inside of Codeigniter. Ideally, I'd like to set the layout in the MY_Controller file for most of the site and change when needed in a controller extending MY_Controller; for instance, setting the main site layout and then for the admin panel setting the admin layout in the Auth_Controller that all of the other admin controllers extend.</p>
  
  <p>Changing the layout of a particular set of templates I'd have to go through and edit all of those files. This doesn't seem ideal. Or even just passing a sidebar data for a particular layout has to be done by passing the sidebar data to each template and from each template to the layout in every file. This seems very redundant. Am I missing something?</p>
  
  <p>To clarify Plates is the template system/library, <a href="http://platesphp.com/" rel="nofollow">http://platesphp.com/</a></p>
  
  <p>Example of what I'm talking about.
  The admin layout has a sidebar of all the admin URLs. This comes from a config file that's loaded and it has it's own template/view file. </p>
  
  <p>I call the template and pass the data from the controller</p>
  
  <pre><code>// I created a library file that extends the Plates library so it can be easily loaded from the CI loader class
  $data['sidebar_data'] = array(
      'navigation'=&gt;'Navigation',
      'assets'=&gt;'Assets',
      'config'=&gt;'Config'
  );
  $data['controller_name'] =&gt; 'Users';
  $this-&gt;plates-&gt;render('admin/whatever_page', $data);
  </code></pre>
  
  <p>Inside of the template file/current page</p>
  
  <pre><code>&lt;?php $this-&gt;layout('layouts/admin', ['title' =&gt; $controller_name, 'sidebar_data' =&gt; $sidebar_data])
  // stuff for this page
  ?&gt;
  </code></pre>
  
  <p>Inside of the sidebar navigation template that gets loaded in the admin layout file</p>
  
  <pre><code>&lt;ul class="menu vertical"&gt;
      &lt;?php foreach($sidebar_data as $url =&gt; $label):?&gt;
      &lt;li&gt;
          &lt;a href="&lt;?= '/admin/' . $url ?&gt;"&gt;&lt;?= $label ?&gt;&lt;/a&gt;
      &lt;/li&gt;
      &lt;?php endforeach; ?&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Then the layout</p>
  
  <pre><code>// there's a HEAD method in here that has the $title variable
  &lt;header class="row expanded collapse"&gt;
          &lt;div class="column"&gt;
              &lt;div class="top-bar"&gt;
                  &lt;div class="top-bar-left"&gt;
                      &lt;ul class="menu"&gt;
                          &lt;li&gt;
                              &lt;a href="/"&gt;&lt;strong&gt;Site Name&lt;/strong&gt;&lt;/a&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
                  &lt;div class="top-bar-right"&gt;
                      &lt;ul class="menu dropdown align-right" data-dropdown-menu&gt;
                          &lt;li&gt;
                              &lt;?= $current_user ?&gt;&lt;/a&gt;
                          &lt;/li&gt;
                          &lt;li class="divider"&gt; | &lt;/li&gt;
                          &lt;li&gt;
                              &lt;?= $this-&gt;insert('auth/logout_form') ?&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/header&gt;
      &lt;section id="content"&gt;
          &lt;div class="left-panel"&gt;
              &lt;?= $this-&gt;insert('adminnav', ['sidebar_data' =&gt; $sidebar_data])?&gt;
          &lt;/div&gt;
          &lt;div class="main-panel"&gt;
              &lt;?= $this-&gt;section('content')?&gt;
          &lt;/div&gt;
      &lt;/section&gt;
      &lt;div id="adminmodal" class="reveal" data-reveal&gt;
          &lt;button class="close-button" type="button" data-close aria-label="Close modal"&gt;
              &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
          &lt;/button&gt;
          &lt;div class="modal-body"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;script type="text/javascript"&gt;$(document).foundation()&lt;/script&gt;
      &lt;?= $this-&gt;insert('_blocks/googleanalytics')?&gt;
  </code></pre>
  
  <p>Having to pass the same data from every controller method to the controller's view/template then from that to the layout/other templates is very redundant.</p>