将自定义css添加到自定义模块

时间:2013-08-01 12:40:38

标签: css xml magento layout

我创建了一个自定义模块,我想添加自定义css样式。我做了一些研究,发现正确的方法是将css添加到正确的文件夹中,然后使用layout.xml添加它。

我的问题是,当我添加css时,我返回了一条错误消息:

Invalid method Namespace_Module_Block_Blockname::addCss(Array([0] => css/mystyle.css))

目前mystyle.css位于

skin/frontend/base/default/css/mystyle.css 

我确实尝试将其添加到

Namespace/Module/css/mystyle.css but without success

我的布局文件如下:

    <handle>
        <block type="modulename/block" name="reference_name" output="toHtml" template="Namespace/Module/filename.phtml" >  
            <action method="addCss"><stylesheeet>css/mystyle.css</stylesheeet></action>      
            <block type="modulename/block" name="reference_name" output="toHtml" template="Namespace/Module/filename.phtml" />
        </block>
    </handle>

在阅读了design_for_magento之后,我也尝试将其包装在默认句柄中,这会产生一个空白屏幕。

在添加此命令之前没有收到任何错误,我做错了什么?

=== EDIT ===

我现在尝试过(在节点中我也试过放置)

<user_preferences>
    <reference name="head">
        <action method="addCss"><link>css/normalize.css</link></action>       
        <block type="prefcentre/returnuser" name="prefcentre_returnuser" output="toHtml" template="ps/prefcentre/returnuser.phtml" >  
            <block type="prefcentre/preferences" name="prefcentre_options" output="toHtml" template="ps/prefcentre/preferences.phtml" />
        </block>
    </reference>   
</user_preferences>

该文件位于前面提到的位置

skin/frontend/default/module/css/mystyle.css 

但这也没有效果

2 个答案:

答案 0 :(得分:0)

addCss行应添加到布局的HEAD部分,而不是块定义中。

例如:

<reference name="head">
     <action method="addCss"><stylesheeet>css/mystyle.css</stylesheeet></action>      
</reference>

请参阅:http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/designing-for-magento

答案 1 :(得分:0)

如果没有看到整个代码,真的可以说得多,但我注意到了一些瓶颈:

  1. 根据布局,您只更新页面user_preferences。这个句柄是否存在,你定义了吗?

  2. 你将块prefcentre / returnuser放入头部而不是身体 - 它应该在那里吗?

  3. 阻止prefcentre / preferences是prefcentre / returnuser的子项。直到最底层(&#39; prefcenter_options&#39); ?&GT;应该在ps / prefcentre / returnuser.phtml模板中调用

相关问题