css - 在 Magento 中为单个页面插入 css 引用的最佳方法

标签 css xml magento block

尝试将对 custom.css 文件的引用添加到 Magento 中的客户仪表板页面时运气不佳。这让我想用 Magento 的眼睛射击,海豹突击队的风格。

根据文档,插入到 customer.xml 中的以下任一项都应该有效:

<reference name="customer_account_dashboard">
    <action method="addCss"><link>dashboardfix.css</link></action>
</reference>

<reference name="customer_account_dashboard">
    <action method="addCss"><stylesheet>css/dashboardfix.css</stylesheet></action>
</reference>

当插入此 block 之前时:

<reference name="my.account.wrapper">
    <block type="customer/account_dashboard" name="customer_account_dashboard" template="customer/account/dashboard.phtml">
        <block type="customer/account_dashboard_hello" name="customer_account_dashboard_hello" as="hello" template="customer/account/dashboard/hello.phtml"/>
        <block type="core/template" name="customer_account_dashboard_top" as="top" />
        <block type="customer/account_dashboard_info" name="customer_account_dashboard_info" as="info" template="customer/account/dashboard/info.phtml"/>
        <block type="customer/account_dashboard_newsletter" name="customer_account_dashboard_newsletter" as="newsletter" template="customer/account/dashboard/newsletter.phtml"/>
        <block type="clientname/account_dashboard_address" name="customer_account_dashboard_address" as="address" template="customer/account/dashboard/address.phtml"/>
    </block>
</reference>

它默默地失败了(没有错误,就好像它根本没有被处理一样)

在 block 之后插入时,我收到“无效方法 Mage_Customer_Block_Account_Dashboard::addCss(Array ( [0] => css/dashboardfix.css ))”错误

dashboardfix.css 与我的其他 Assets 位于 skinname/css 文件夹中。

有什么想法吗?

最佳答案

您的代码中存在一个小的语法错误 - 请参阅下面更正后的代码。

此外,要使其正常工作,您需要 macguffin.css将文件放在与 styles.css(或 boxes.css)相同的 css 文件夹中,即主题的 css 文件夹。

您可能还想关闭 css 文件的缓存和合并,以确保其正常工作。

这是你应该如何拥有完整的 block :

<!--
Customer account pages, rendered for all tabs in dashboard
-->

<customer_account translate="label">
    <label>Customer My Account (All Pages)</label>
    <!-- Mage_Customer -->
    <reference name="head">
        <action method="addCss"><stylesheet>css/macguffin.css</stylesheet></action>
    </reference>
    <reference name="root">
        <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
    </reference>
    <reference name="content">
        <block type="page/html_wrapper" name="my.account.wrapper" translate="label">
            <label>My Account Wrapper</label>
            <action method="setElementClass"><value>my-account</value></action>
        </block>
    </reference>

    <reference name="left">
        <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
            <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
            <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
            <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
        </block>
        <remove name="tags_popular"/>

    </reference>
</customer_account>

请记住,只要您的 css 文件名为 macguffin.css一切都会好起来的。

关于css - 在 Magento 中为单个页面插入 css 引用的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6681449/

相关文章:

xml - 使用 xslt 有条件地添加默认命名空间

MySql 停止写入,但继续读取

php - 如何在 Magento 仪表板图中显示挂单

php - Magento 订单表 : custom column

jquery - z-index问题,图像重叠div

javascript - 如何在着陆页菜单上制作 jQuery 从上到下滚动和从下到上慢速动画

jquery - 在 AJAX 中解析 xml 响应的最佳方式是什么

css - 如何更改 Vaadin 10 中组合框的样式

html - 如何在部分中添加背景颜色?

php - 文件类型字段在文件字段下方显示最大上传大小。需要在 joomla 中删除它