2

There are two ways to set a blocks template. Either in the block using

$this->setTemplate('Vendor_Module::template.phtml');

or in layout

<block class="Vendor\Module\Block\BlockName" name="myblock"template="Vendor_Module::template.phtml"/>

Which way would be the best way to set a blocks template or what are the advantages/disadvantages of both?

1 Answer 1

2

Prefere setting template in layout, so it could be extended easily in other modules just using layout.

If you have to set template depending on a condition, you could do it programmatically in block, just think of extensibility by using a public function (so it could be extended by plugin)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.