![](/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.