title: ZF2 Partial ViewHelper
body: <p>Editing the original post to be more clear. Now there is a new area of trouble that I believe is pure syntax. </p>
  
  <p>I'm new to OOP and Zend Framework 2. Trying to understand the use of partials. I'm also extending an application first started by someone else. So the naming convention of the Entity/Gateway/Controller/View ensure that for a specified action, the correct template is returned. </p>
  
  <p>I'm trying to use "partial('/nav/index.phtml');" as a way of inserting one snippet in the header on the index page. But I want to use a different partial on other pages. </p>
  
  <p>Following Marshall's suggestion, in the TemplateController, I am adding a variable (nav_template) to the viewModel specifying which partial to use for the navigation:</p>
  
  <pre><code>    &lt;?php
  
      namespace Application\Controller;
  
      use Zend\Mvc\Controller\AbstractActionController;
      use Zend\View\Model\ViewModel;
  
      class TplController extends AbstractActionController
      {
          public function topicAviewAction()
          {
              $viewModel = new ViewModel();
              $viewModel-&gt;setTerminal(true);
          $viewModel-&gt;setVariable('nav_template', 'nav/topica.phtml');
              return $viewModel;
          }
  
          public function topicBviewAction()
          {
              $viewModel = new ViewModel();
              $viewModel-&gt;setTerminal(true);
          $viewModel-&gt;setVariable('nav_template', 'nav/topicb.phtml');
              return $viewModel;
          }
      }
  </code></pre>
  
  <p>I used the below command to verify that my variable was being included in the object, which it was</p>
  
  <pre><code>    echo $viewModel-&gt;nav_template;
  </code></pre>
  
  <p>However, when I go to include the partial in layout.phtml using the following:</p>
  
  <pre><code>    &lt;?php echo $this-&gt;partial(isset($nav_template) ? $nav_template : 'nav/index'); ?&gt;
  </code></pre>
  
  <p>It is obviously not using/finding the value of $nav_template. Where did I go wrong?</p>