【问题标题】:adding custom css to a custom module将自定义 CSS 添加到自定义模块
【发布时间】:2013-08-02 09:27:09
【问题描述】:

我创建了一个自定义模块,我想将自定义 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>

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

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

===编辑===

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

<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 

但这也没有用

【问题讨论】:

    标签: css xml magento layout


    【解决方案1】:

    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

    【讨论】:

    • 感谢您的链接,我已尽我所能遵循并实施了这些示例。但仍然未能使其发挥作用。请查看我的编辑,任何建议都会被采纳
    【解决方案2】:

    没有看到整个代码真的不能说太多,但这里有一些我注意到的瓶颈:

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

    2. 您将块 prefcentre/returnuser 放入头部而不是正文 - 它应该在那里吗?

    3. 块 prefcentre/preferences 是 prefcentre/returnuser 的子级。 getChildHtml('prefcenter_options'); ?> 应该在 ps/prefcentre/returnuser.phtml 模板中调用

    【讨论】:

      猜你喜欢
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      相关资源
      最近更新 更多