我正在创建一个模块来添加一些额外的号召性用语按钮。我无法显示输出。我相信我的命名约定或文件位置(或两者)都错误。

这也可能是我尝试插入块的方式。如果可以避免的话,我不想修改 phtml 文件。

正如你从我的文件中看到的,我正在尝试多种方法来获取 任何事物 被输出 - 没有运气。

目的是能够在添加到购物车后添加其他 CTA 按钮 - 例如“请求样品”

文件结构:

app
    Code
        local
            CompanyName
                CtaAttributes
                    Block -> CtaButtons.php
                    etc -> config.xml
    design
        frontend
            base
                default
                    layout->ctabuttons.xml
                    template
                        ctaattributes
                            catelog
                               product ->ctabuttons.phtml

配置文件

<config>

    ... includes Module and Resource

    <global>
      <blocks>
        <ctaattributes>
            <class>CompanyName_CtaAttributes_Block</class>
        </ctaattributes>
      </blocks>
    </global>

</config>

CtaButtons.xml

<?xml version="1.0"?>

<layout version="0.1.0">
    <catalog_product_view>    
        <reference name="content">

                <block type="core/text_list" name="product.info.addtocart" before="addtocart" template="ctaattributes/catalog/product/ctabuttons.phtml"/>
                <action method="append">
                        <block>ctabuttons</block>
                </action>
        </reference>

        <reference name="product.info.addtocart">
            <block type="core/text_list" name="core-text"><action method="setText"><text><![CDATA[<div>Test</div>]]></text></action></block>
        </reference>
    </catalog_product_view>    
</layout>

ctabuttons.phtml

<?php
/**
*/
Mage::log(get_class($this));
echo 'this is my test';

CtaButtons.php

<?php

class CompanyName_CtaAttributes_Block_CtaButtons extends Mage_Core_Block_Template  {
    echo 'test';

}
有帮助吗?

解决方案 4

我找到了一个解决方案 - 它分为两部分。

  1. 我没有为布局更新定义前端->更新路径。我在之后插入了这个 </global>

      <frontend>
        <layout>
            <updates>
                <ctaattributes>
                    <file>ctaattributes.xml</file>
                </ctaattributes>
            </updates>
        </layout>  
    </frontend>
    

如果我使用 local.xml,我不认为这是必需的,但在我的测试中,我认为我应该更改文件名以将其分开。

  1. 您不能在块类名称中使用驼峰式大小写

原来我的课是 CompanyName_CtaAttributes_Block_CtaButtons - 对应的文件名为 CtaButtons.php.
将名称更改为 CompanyName_CtaAttributes_Block_CtabuttonsCtabuttons.php 已解决问题。

不知道是Block/Blockname.php中的Class文件有问题还是layout xml文件有问题。

我已经在公司名称和模块中使用 CamelCase 对此进行了测试,没有影响,它似乎仅限于 Blockname 类和文件。

其他提示

  • /blocks/ctabuttons.xml在文件结构中应该是php 文件。
  • 我没有看到应该在/ app / etc / modules
  • 中的模块文件
  • 您应该在config.xml
  • 中具有模块版本控制

如果使用最新的修补程序,也应在系统中允许块 - >权限 - >块

嗨,您需要定义块类型第一个

<?xml version="1.0"?>

 <layout version="0.1.0">
     <catalog_product_view>    
         <reference name="content">

                 <block type="core/text_list" name="product.info.addtocart" before="addtocart" template="ctaattributes/catalog/product/ctabuttons.phtml"/>
                 <action method="append">
                         <block>ctabuttons</block>
                 </action>
         </reference>

         <reference name="product.info.addtocart">
             <block type="core/text_list" name="core-text"><action method="setText"><text><![CDATA[<div>Test</div>]]></text></action></block>
         </reference>
     </catalog_product_view>    
 </layout>
.

<?xml version="1.0"?>

<layout version="0.1.0">
    <catalog_product_view>    
        <reference name="product.info">
            <block type="core/text_list" name="product.info.ctaattributes" before="addtocart" template="ctaattributes/catalog/product/ctabuttons.phtml"/>
        </reference>
    </catalog_product_view>    
</layout>
.

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