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


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


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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.