TreeLayoutStack is a module for ZF2 allowing the creation of tree layout
This project is maintained by neilime
NOTE : If you want to contribute don't hesitate, I'll review any PR.
TreeLayoutStack is module for ZF2 allowing the creation of tree layout
./vendor/
directory.Add this project in your composer.json:
"require": {
"neilime/zf2-tree-layout-stack": "dev-master"
}
Now tell composer to download TreeLayoutStack by running the command:
$ php composer.phar update
Enabling it in your application.config.php
file.
<?php
return array(
'modules' => array(
// ...
'TreeLayoutStack',
),
// ...
);
This example shows how to define a simple tree layout stack with header and footer parts
After installing skeleton application, install TreeLayoutStack as explained above.
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'
//...
)
)
//...
);
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
//...
Create header and footer view files
module/Application/view/layout/header.phtml
module/Application/view/layout/footer.phtml
Save & Resfresh.
layout_tree
: Define the layout tree, you can define differents tree layout stack, depends on module name, the default
configuration is used if no template is defined for current module layout_tree
entry) :layout_tree
entry or template
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
)
)
)
)
)
),
//...
);
```