Zf2-tree-layout-stack

TreeLayoutStack is a module for ZF2 allowing the creation of tree layout

This project is maintained by neilime

TreeLayoutStack, v1.0

Build Status Latest Stable Version Total Downloads Code coverage

NOTE : If you want to contribute don't hesitate, I'll review any PR.

Introduction

TreeLayoutStack is module for ZF2 allowing the creation of tree layout

Requirements

Installation

Main Setup

By cloning project

  1. Clone this project into your ./vendor/ directory.

With composer

  1. Add this project in your composer.json:

    "require": {
        "neilime/zf2-tree-layout-stack": "dev-master"
    }
    
  2. Now tell composer to download TreeLayoutStack by running the command:

    $ php composer.phar update
    

Post installation

  1. Enabling it in your application.config.phpfile.

    <?php
    return array(
        'modules' => array(
            // ...
            'TreeLayoutStack',
        ),
        // ...
    );
    

    How to use TreeLayoutStack

Simple configuration example

This example shows how to define a simple tree layout stack with header and footer parts

  1. After installing skeleton application, install TreeLayoutStack as explained above.

  2. Edit the application module configuration file module/Application/config/module.config.php, adding the configuration fragment below:

    <?php
    return array(
        //...
        'tree_layout_stack' => array(
            'layout_tree' => array(
                'default' => array(
                    'template' => 'layout/layout',
                    'children' => array(
                        'header' => 'header/header',
                        'footer' => 'footer/footer'                                     
                    )
                )
            )
        ),
        //...
        'view_manager' => array(
            'template_map' => array(
                //...
                'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
                'header/logged' => __DIR__ . '/../view/layout/header.phtml',
                'footer/footer' => __DIR__ . '/../view/layout/footer.phtml'
                //...
            )
        )
        //...
    );
    
  1. Edit layout file module/Application/view/layout/layout.phtml, adding header and footer where you want to display them

        //...
        echo $this->header; //Display header part
        //...
    
        //...
        echo $this->layout()->content; //Display content part
        //...
    
        //...
        echo $this->layout()->footer; //Display footer part
        //...   
    
  2. Create header and footer view files module/Application/view/layout/header.phtml module/Application/view/layout/footer.phtml

  3. Save & Resfresh.

Configuration

  1. TreeLayoutStack :
  1. Module layout tree map (layout_tree entry) :

Complexe exemple

This example shows all the configuration options available, it assume that template_map is properly defined in view_manager configuration

```php
<?php
return array(
    //...
    'tree_layout_stack' => array(
        'layout_tree' => array(
            'default' => array(
                'template' => 'layout/layout',
                'children' => array(
                    'header' => function(\Zend\Mvc\MvcEvent $oEvent){
                        return $oEvent->getViewModel()->isLoggedUser?'header/logged':'header/unlogged' // Current MVC event is passed as argument to the callable template
                    },
                    'footer' => array(
                        'template' => 'footer/footer',
                        'children' => array(
                            'social' => 'footer/social',
                            'sitemap' => array('SampleClass','SampleFunction') //Sample callback
                        )
                    )                                   
                )
            )
        )
    ),
    //...
);
```