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

时间:2011-07-13 15:31:11

标签: 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>

在此块之前插入时:

<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>

它无声地失败(没有错误,就像它根本没有处理过一样)

块之后插入时,我得到一个“无效方法Mage_Customer_Block_Account_Dashboard :: addCss(Array([0] =&gt; css / dashboardfix.css))错误

dashboardfix.css 与我的其他资产一起位于skinname / css文件夹中。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您的代码中存在轻微的语法错误 - 请参阅下面的更正代码。

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

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

以下是完成块的方法:

<!--
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,它就会很好。