【问题标题】:Magento - Add phtml file to layout blockMagento - 将 phtml 文件添加到布局块
【发布时间】:2011-08-13 22:02:38
【问题描述】:

我正在尝试添加一些代码,这些代码将在产品页面上直接在产品价格下方显示文本 - 此外,我尝试通过“Magento”方式执行此操作,不仅将代码复制到 view.phtml 中,还通过创建at 块,然后在布局文件中引用该块。

无论好坏,我都在努力关注this tutorial

到目前为止,我已经创建了包含我想要显示的内容的 phtml 文件 (sharethis.phtml) 在页面 xml 中创建了一个引用:

<block type="core/text_list" name="sharethis" as="sharethis"/>

就在这个块之后

<block type="core/text_list" name="left" as="left" translate="label">
<label>Left Column</label>
</block>

在 catalog.xml 中引用了该引用,就在第一个默认标记之后:

    <reference name="sharethis">
        <block type="catalog/product_new" name="sharethis" template="catalog/product/view/sharethis.phtml"/>
    </reference>

最后像这样从 view.phtml 文件中调用该块

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

但它没有出现。有什么建议吗?

【问题讨论】:

    标签: magento


    【解决方案1】:

    您是否要添加结构块?或者只是价格下方的一个街区?因为它们不同。如果我了解您在 catalog.xml(布局文件)中尝试做什么,请添加:

    <catalog_product_view>
       ...
       <reference name="content">
           <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
            <!--- ADD THIS -->
               <block type="catalog/product_new" name="sharethis" template="catalog/product/view/sharethis.phtml"/>
            <!-- END ADD -->
           ...
           </block>
        ...
        </reference>
        ...
    </catalog_product_view>
    

    基本上要回显子块,所述块必须是您所在块的子块。

    另外你的类型可能是错误的,请确保你使用的是正确的类型。

    【讨论】:

    • 您放置块的位置取决于您试图让块显示的确切位置。 ...因此,如果这不起作用,我需要知道您尝试将“sharethis”块放入哪个块
    【解决方案2】:

    我认为您不能拥有 2 个具有相同名称的块(这就是您将得到的,因为您声明了 2 个块“sharethis”)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多