Zend_Layout: Layouts per module
by Patrick on July 24, 2009
Today I was confronted with the problem to assign a single layout.phtml to each module of a Zend Application. At first I thought it’d be done easily with an application.ini line like this one:
admin.resources.layout.layoutPath = path/to/layout
(whereas “admin” is the module name). But as often, pressing F5 brought disillusion, it doesn’t work this way.
A quick Google search said, that writing a Front Controller plugin which searches for a layout.phtml file by module name is the solution to all my problems. Actually this was exactly what I wanted, but there had to be a way without adding extra code to the application.
So I didn’t settle with this plugin and tried some other things until an error message opened my eyes. In fact, Zend also searches for layout files in the /scripts/views/ dir of each module. Everything I had to do was removing the “resources.layout.*” settings from my application.ini and adding a layout.phtml file to each of the latter named dirs and – voilà – each module used his own layout script; awesome, isn’t it?
One comment
Thanks, this helped a lot. Knew there had to be a better way than breaking out a Zend_Layout plugin.
by David Valentiate on April 13, 2010 at 1:16 am #