Note that there are some explanatory texts on larger screens.

plurals
  1. POSet specific layouts files in ZF2
    text
    copied!<p>I want built my ZF2 source to get specific layouts by module hierarchy</p> <p>Then if the templates file exists, i want map it to current module</p> <p>Ex:</p> <ul> <li>templates/album/profile/list.phtml : Module "Album" => Controller "Profile" => Action "List"</li> <li>templates/album/album.phtml : For all "Album" module</li> <li>templates/layout/layout.phtml : Default template for another module</li> </ul> <p>======================================</p> <p>I got this in ZF2 Skeleton Apps</p> <pre><code>'view_manager' =&gt; array ( 'display_not_found_reason' =&gt; true, 'display_exceptions' =&gt; true, 'doctype' =&gt; 'HTML5', 'not_found_template' =&gt; 'error/404', 'exception_template' =&gt; 'error/index', 'template_map' =&gt; array ( 'layout/layout' =&gt; __DIR__ . '/../../../template/layout/layout.phtml', 'layout/custom' =&gt; __DIR__ . '/../../../template/layout/custom.phtml', 'error/404' =&gt; __DIR__ . '/../../../template/error/404.phtml', 'error/index' =&gt; __DIR__ . '/../../../template/error/index.phtml' ), 'template_path_stack' =&gt; array ( __DIR__ . '/../view' ) ) </code></pre> <p>I can set custom layout by this way</p> <pre><code>$e-&gt;getApplication()-&gt;getEventManager()-&gt;getSharedManager()-&gt;attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) { $controller = $e-&gt;getTarget(); $controller-&gt;layout('layout/custom'); } </code></pre> <p>But i must define 'template_map' manually. Is there any ways to set current controller specific template file ? I want something like this </p> <pre><code>//Set template $template = 'layout/layout'; if (file_exists($templatePath . $currAction.'.phtml')) { $template = $currAction; }else if(file_exists($templatePath . $currController.'.phtml')) { $template = $currController; }else if(file_exists($templatePath . $currModule.'.phtml')) { $template = $currModule; }else{ //return default template } $controller-&gt;layout($template); </code></pre> <p>Thanks</p> <p>================</p> <p>Update 11/27/2012 :</p> <p>I found some simple way to map layout key:</p> <p>In module.config.php just adding an addition path</p> <pre><code>'view_manager' =&gt; array ( ..... 'template_path_stack' =&gt; array ( __DIR__ . '/../view/', __DIR__ . '/../../../template/' ) ) </code></pre> <p>Then i can use template hierarchy system. BUT only for module and controller level. My problem is the layout and "action view" conflict</p> <ul> <li>/template/album.phtml => work fine. Apply template all "album" module</li> <li>/template/album/profile.phtml => work fine. Apply template all "album/profile" controller</li> <li>/template/album/profile/detail.phtml => It's conflict with "modules/album/view/album/profile/detail.phtml" . Then it's got wrong view by set layout file to view</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload