Domanda

I'm working with reusable modules in Zend2 and I have a little problem which concerns code duplication.

I have an User module, which has i.e an HTML template register (template path: user/user/register). It contains some basic HTML but in one of my projects, I need to embed this template with a < div > for CSS stylization (the rest of the HTML page doesn't change).

After the User module, I load my Application module where I can overwrite the user/user/register template and put new code but I'm unable to render the original user/user/register template through it.

Example of code in Application module -> user/user/register:

<div><?=$this->render('user/user/register')?></div>

This causes an endless loop and I don't want to copy/paste all the HTML from my user/user/register template in User module.

Anyone can help me ?

Thank you !

È stato utile?

Soluzione

What you're trying to achieve won't work. You can not have two templates with identical names. The Module that loads the key the latest will always have priority.

You have to understand that templates are just a key inside a big array.

'view_manager' => array(
    'template_map' => array(
        'layout/layout' => 'my\layout.phtml'
    )
)

So if you have two modules providing this configuration, it doesn't change the fact that both use the key layout/layout. Therefore whatever Module loads later, wins.

TL/DR You can only overwrite templates, not extend them. In your case you have to create a separate template.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top