简体   繁体   English

如何在magento .phtml文件中渲染块?

[英]How to render a block in magento .phtml file?

I am trying to render the magento contact form into a .phtml file, but I cannot find anything on Google to get the PHP code to do it. 我试图将magento联系表单呈现为.phtml文件,但我在Google上找不到任何可以获取PHP代码的内容。

I only know the code to use in magento's CMS system which is: 我只知道在magento的CMS系统中使用的代码是:

{{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}

Any clues? 有线索吗?

只要XML块正确放置,在phtml文件中你就应该能够将它带出来:

<?php echo $this->getChildHtml('contactForm') ?>

If you want to have the contact form with in a phtml page then... 如果你想在一个phtml页面中有联系表格,那么......

  1. add the block to the xml you want for example I wanted to add a request form to the product view so, i went to catalog.xml at the <reference name="content"> and add: 将块添加到您想要的xml中,例如我想将一个请求表单添加到产品视图中,因此,我转到<reference name="content"> catalog.xml并添加:

     <block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"/> 
  2. just add the getChildHtml : 只需添加getChildHtml

    getChildHtml('contactForm') ?> getChildHtml('contactForm')?>

So simple, I know, but took me 3 coffees like all easy things in magento... 我知道,这么简单,但是我带了3个咖啡,比如magento中的所有简单的东西......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM