PHP code example of neilime / zf2-tree-layout-stack

1. Go to this page and download the library: Download neilime/zf2-tree-layout-stack library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neilime / zf2-tree-layout-stack example snippets


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

	
	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'
				//...
			)
		)
	    //...
	);
	
3. Edit layout file `module/Application/view/layout/layout.phtml`, adding header and footer where you want to display them
	

	
	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
							)
						)									
					)
				)
			)
	    ),
	    //...
	);
	
bash
    $ php composer.phar update