![](/img/trans.png)
[英]Magento 2 - How to call a custom phtml file in another phtml file, xml layout, static block and cms page
[英]How to call a static block of magento extension in .phtml file?
我在主頁上安裝了滑塊擴展程序。 它給了我一個靜態的塊代碼。
Call via block:
{{block type="responsivebannerslider/index" name="responsivebannerslider_index" template="responsivebannerslider/index.phtml"}}
不知道如何在.phtml文件中調用它?
您可以通過直接在phtml模板文件中的布局上創建一個塊來從模板中調用它:
<?php echo $this->getLayout()->createBlock('responsivebannerslider/index')->setTemplate('responsivebannerslider/index.phtml')->toHtml(); ?>
或者,如果該塊在擴展布局XML文件中列出(該塊將嵌套在參考節點中),則其外觀類似於:
<block type="responsivebannerslider/index" name="responsivebannerslider_index" as="an_alias" template="responsivebannerslider/index.phtml">
<label>Responsive banner</label>
</block>
您可以在模板文件中調用它,例如:
<?php echo $this->getChildHtml('an_alias'); ?>
<?php echo $this->getLayout()->createBlock('responsivebannerslider/index')->setTemplate('responsivebannerslider/index.phtml')->toHtml(); ?>
\n
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.