Search code examples
phpviewlithium

Different views in one


I´m working on a project using lithium framework and I need to be able to have different views in a "MAIN" view.

For example. I have to be able to see the post and events forms (add a new event and a new post) in the principal view.

I actually have the view for add a new post and a new event. I´m looking the way to include this views in the main one.

Any idea of how to solve this? Thanks in advance


Solution

  • $this->_render() is used within the views to include elements. Any variables passed from the controller to the parent view are also available in the element. The third argument of $this->_render() can be used to pass additional variables.

    <?php
    
    // renders app/views/elements/nav.html.php
    echo $this->_render('element', 'nav');
    
    ?>
    

    Relative pathing works, so if you want to reuse a template from say app/views/events/add.html.php, you can do this:

    <?=$this->_render('element', '../events/add'); ?>