我正在尝试使用布局 xml 在价格之前将核心模板文件插入到产品视图页面中。

我已经尝试过这个。

<catalog_product_view>
    <reference name="content">
        <block type="core/template" name="myblock" as="myblock" template="mymodule/mytemplate.phtml"/>
    </reference>
</catalog_product_view>

但它显示在内容底部、页脚之前。

然后我尝试添加 before="product.info.simple"

<catalog_product_view>
    <reference name="content">
        <block type="core/template" name="myblock" as="myblock" template="mymodule/mytemplate.phtml" before="product.info.simple"/>
    </reference>
</catalog_product_view>

但它显示在面包屑之后的内容之上。

那么,有人知道如何让它显示在价格之前吗?

有帮助吗?

解决方案

问题是您只能向一个具有的块添加一个块 core/text_list 类型。因此,您需要找到最接近的类型块,直到要定位块的地方。

如果您只想将其用于简单产品(这是不可能的),则可以做这样的事情:

<?xml version="1.0"?>
<layout>
    <PRODUCT_TYPE_simple>
        <reference name="product.info.simple.extra">
            <block type="core/template" name="test" template="test.phtml" before="-"/>
        </reference>
    </PRODUCT_TYPE_simple>
</layout>

对于所有类型的产品,这是您可以获得的最接近:

<?xml version="1.0"?>
<layout>
    <catalog_product_view>
        <reference name="alert.urls">
            <block type="core/template" name="test" template="test.phtml" after="-"/>
        </reference>
    </catalog_product_view>
</layout>

其他提示

另一种方法是更改​​目录/产品/视图模板并添加

$this->getChildHtml('my_cool_block_name');

并将其添加到 local.xml

<catalog_product_view>
    <reference name="product.info">
        <block type="core/template" name="my_cool_block_name" template="test.phtml" after="-"/>
    </reference>
</catalog_product_view>
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('mymodule/mytemplate.phtml')->toHtml(); ?>

您正在使用此代码的任何地方。

许可以下: CC-BY-SA归因
scroll top