AnswerBun.com

is creating block within template in magento 2 good practice

Magento Asked by Herve Tribouilloy on July 24, 2020

I often see in phtml templates blocks being creating dynamically like below:

$block->getLayout()->createBlock(BlockClass)->toHtml();

I worry whether this is good practice and particularly whether the block will be cached eventually or whether it can create an overhead in the page load?

Has anybody any ideas whether the cache is not applying for these blocks?

Add your own answers!

Related Questions

Magento 2 call APIexternal

1  Asked on November 27, 2021

   

Override method in LayoutProcessor

2  Asked on November 25, 2021 by creativename

       

Magento 2: How to set default layout to 1column

2  Asked on November 25, 2021 by nhinzky

   

Magento 2 Forgot Password page incorrect captcha

4  Asked on November 25, 2021 by mahmoudismail

         

Magento2: How to redirect minicart on checkout cart page?

3  Asked on November 25, 2021 by ravi-soni

     

magento 2 order grid loading issue after data migration

4  Asked on November 25, 2021 by nagaraju-kasa

         

Different locations for search bar depending on width

1  Asked on November 25, 2021 by jannis-s

     

Insert a custom block into another custom block, in Magento 2

1  Asked on November 25, 2021 by danilomorowinstech

   

How to Show Cart Discount in magento 2

1  Asked on November 25, 2021

 

How to set region value in checkout page?

1  Asked on November 25, 2021 by nubitol

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir