New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML syntax to change block's template #3356

cescopag opened this Issue Feb 10, 2016 · 13 comments



cescopag commented Feb 10, 2016


Documentation claims that it is possible to change a block's template by the following layout update:

<referenceBlock name="navigation.sections">
    <argument name="template" xsi:type="string">Magento_Theme::html/nav_sections.phtml</argument>

But It doesn't work.

Using action node, instead of arguments node, works fine:

<referenceBlock name="navigation.sections">
  <action method="setTemplate">
    <argument name="template" xsi:type="string">Magento_Theme::html/nav_sections.phtml</argument>



Proposed solution


This comment has been minimized.


shiftedreality commented Mar 10, 2016

Hi @cescopag

You provided correct way with action method
Looks like mistake in public docs


This comment has been minimized.

almarchenko commented Mar 14, 2016

Hi @cescopag!
Thank you for reporting this. Looks like there's a bug in magento code, that is why the code sample provided in docs doesn't work. But you found the correct temporary solution.
It must be temporarily as is deprecated. I'll add a note in docs, and updated them when the bug is fixed.


This comment has been minimized.

LiamFielding commented Aug 22, 2016

Is this now fixed?


This comment has been minimized.

dnadle commented Aug 23, 2016

In 2.1.0 I still have to use 'action' and the online documentation is still wrong.


This comment has been minimized.

LiamFielding commented Sep 9, 2016

@digitalpianism No, sorry - I believe that's what we all tried first. At least I did, that's how I ended up here.


This comment has been minimized.


digitalpianism commented Sep 9, 2016

@LiamFielding my bad. I guess we gotta wait ^^

@vzabaznov vzabaznov self-assigned this Oct 4, 2016


This comment has been minimized.


diglin commented Nov 2, 2016

The reason why it doesn't work is because the method \Magento\Framework\View\Layout\Generator\Block::generateBlock:

When we want to overwrite an existing block, this one was at first initialized via a layout XML with an attribute template.

Into the generateBlockmethod, arguments are passed to the block, then setTemplate is called and then in the calling method process the action is called.

So the priority is the following:

  • actions
  • setTemplate via attribute template
  • arguments

When a block was initialized with its attribute template, arguments will have no effect. That's why you need to use actions

protected function generateBlock(
        Layout\ScheduledStructure $scheduledStructure,
        Layout\Data\Structure $structure,
    ) {
        list(, $data) = $scheduledStructure->getElement($elementName);
        $attributes = $data['attributes'];

        if (!empty($attributes['group'])) {
            $structure->addToParentGroup($elementName, $attributes['group']);
        if (!empty($attributes['display'])) {
            $structure->setAttribute($elementName, 'display', $attributes['display']);

        // create block
        $className = $attributes['class'];
        $block = $this->createBlock($className, $elementName, [
            'data' => $this->evaluateArguments($data['arguments'])
        if (!empty($attributes['template'])) {
        if (!empty($attributes['ttl'])) {
            $ttl = (int)$attributes['ttl'];
        return $block;

This comment has been minimized.


nsergo commented Mar 16, 2017

Issue in progress @nsergo & @sambolek


This comment has been minimized.


magento-team commented Jul 31, 2017

Internal ticket to track issue progress: MAGETWO-66248


This comment has been minimized.


magento-engcom-team commented Sep 20, 2017

Closing the issue as the feature request. Please, see more details here #8913 (comment)


This comment has been minimized.

tmotyl commented Sep 20, 2017

@magento-engcom-team the PR you've referencing was also closed, as it required some changes in the pull request code.
So now both this issue and PR are closed but the issue still exists and documentation is still wrong.
In my opinion this issue should stay open until it's fixed.

If you consider this a feature request, please at last fix the documentation.

@magento-engcom-team magento-engcom-team moved this from TODO to Done in branch [2.3-develop] Sep 20, 2017


This comment has been minimized.


DanielRuf commented May 8, 2018

This issue still exists. We should reopen it.


This comment has been minimized.

engcom-backlog-pb commented Sep 13, 2018

@cescopag, thank you for your report.
We've acknowledged the issue and added to our backlog.

@engcom-backlog-pb engcom-backlog-pb removed their assignment Sep 13, 2018

zetlen pushed a commit to magento-research/magento2 that referenced this issue Oct 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment