Question

I want to change the template with block name "persistent.remember.me", but there are two blocks with that same name under the same handle:

app/design/frontend/base/default/layout/persistent.xml

<checkout_onepage_index>
    <reference name="checkout.onepage.login">
        <action method="setTemplate"><template>persistent/checkout/onepage/login.phtml</template></action>
        <block type="persistent/form_remember" name="persistent.remember.me" template="persistent/remember_me.phtml" />
    </reference>
    <reference name="checkout.onepage.billing">
        <action method="setTemplate"><template>persistent/checkout/onepage/billing.phtml</template></action>
        <block type="persistent/form_remember" name="persistent.remember.me" template="persistent/remember_me.phtml" />
        <block type="core/template" name="persistent.remember.me.tooltip" template="persistent/remember_me_tooltip.phtml" />
    </reference>
</checkout_onepage_index>

I have created a local.xml with the following contents:

app/design/frontend/mytheme/default/layout/local.xml

<checkout_onepage_index>
    <reference name="persistent.remember.me">
        <action method="setTemplate"><template>mytheme/persistent/remember_me.phtml</template></action>
    </reference>
</checkout_onepage_index>

And everything works fine; Only the template of the last reference ("checkout.onepage.billing") gets updated, which is exactly what I want, but I'm not sure why it does this. I was under the impression that block names should always be unique. Is this a bug in Magento? What could happen to this code if I upgrade Magento?

Was it helpful?

Solution

Erfan is right that the html is outputted twice, once as a child of 'checkout.onepage.login' and once as a child of 'checkout.onepage.billing'

Thus there are two child blocks with the same name. Each can have a different template, and each gets rendered as a child of the parent.

To change the persistent block in either of the parent blocks, you need to target the parent block directly such as:

<checkout_onepage_index>
    <reference name="checkout.onepage.login">
            <block type="persistent/form_remember" name="persistent.remember.me" template="my/custom/template.phtml" />
        </reference>
</checkout_onepage_index>

The above will only change the template in the login block.

If you only target the child block 'persistent.remember.me' then magento seems to only change the occurrence of the first found block. Start Speculation: This is most likely in order or alpha occurrence , with 'checkout.onepage.billing' appearing alphabetically before 'checkout.onepage.login', in whatever array is used to store the block internally. The fact that .billing is rendered after .login just makes it look like it is only changing the second occurrence. :) End Speculation

OTHER TIPS

No this is no bug. I bet there is only one block on the site out of "checkout.onepage.billing" and "checkout.onepage.login".

So there is only one block "persistent.remember.me".

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top