Freitag, 30. November 2012

Create System Wide Views/Layouts

I have been contemplating on how to go about this. I read a couple of tutorials offering multiple solutions like creating an extra module for this, creating custom view helpers just to name a few.
The more you get involved in this new framework, the more you'll know about its feasibility. Lets start off creating views that can be accessed by all modules in your application::
  1. Create a folder in your module directory i.e the directory where all your modules reside. I will call this folder globalViews. create the view folders you need in this newly created folder and add your view scripts in there, for example: globalViews/header/header.phtml, globalViews/footer/footer.phtml
  2. You can now do module specific settings to use these views. Go to your module_config.php file which resides in the config folder of your module and do the following:
    • In the template_path_stack array, add your newly created globalView folder so that the views can be loaded:
      
       'template_path_stack' => array(
                  __DIR__ . '/../view',
                   __DIR__ . '/../../globalViews',
              ),
      
      
  3. We are now done with the configuration, we can now call those views in our respective layouts in our modules. To do so, we shall be using the partial helper.
    To add the footer in your layout, just do this
    
      partial("footer/footer.phtml"); ?>
    

    . You are done !!!

Keine Kommentare:

Kommentar veröffentlichen