title: Dynamic Views in ZF2
body: <p>I am working on my SaaS app which is going to require a Custom ViewModel to be built to populate widgets (left,center,right,footer, etc)</p>
  
  <p>I started off using a BaseController</p>
  
  <pre><code>`class BaseController extends AbstractActionController {`
  </code></pre>
  
  <p>But since I am going to try to use modules like ZfcUser etc  I was wondering can I create a module that builds the ViewModel and if so where/how should I hook into the event to not break forwards/redirects?</p>
  
  <p>My thought is build the larger view model without interfering with normal controller behaviors. The controllers would just pass back their normal array() for the viewmodel and it would be placed it </p>
  
  <pre><code>  `&lt;?php echo $this-&gt;content; ?&gt;`
  </code></pre>
  
  <p>Ok clarification on a website you generally have Header, Footer, Content and say Left Nav. So the footer has 3 columns Login Box, Lastest News, and twitter feed, the left nav has Navigation and some ad's</p>
  
  <p>All this really doesnt pertain to the Controller and Action being called so I am trying to find the best place to fetch the ViewModel and how then build and populate with all these external entities (login template,twitter, Nivo Slider) and replace.</p>
  
  <p>Then when the controller returns its array() have it replace the <code>$this-&gt;content</code> in the layout</p>
  
  <p>Putting all this in each Action would be huge and would break outside module use. </p>