Magento ::如何使用local.xml将模板添加到打印页面

时间:2015-02-12 16:10:27

标签: xml magento

我正在尝试使用设计文件夹中的local.xml将样式表添加到Magento的打印pagina。

我正在尝试从销售/订单/明细页面打印。我知道这不会打印出打印文档的样式,但它会设置html文档的样式

这是我在local.xml中的内容:

 <print>
      <block type="page/html" name="root" output="toHtml" template="page/print.phtml">
        <block type="page/html_head" name="head" as="head">
            <action method="addCss" name="global">
                <stylesheet>css/global.css</stylesheet>
            </action>
        </block>
      </block>
     </print>

这就是我从page.xml中提取的内容。这是基本page.xml中的内容:

<print translate="label" module="page">
        <label>All Pages (Print Version)</label>
        <!-- Mage_Page -->
        <block type="page/html" name="root" output="toHtml" template="page/print.phtml">

            <block type="page/html_head" name="head" as="head">
                <action method="addJs"><script>prototype/prototype.js</script></action>
                <action method="addJs"><script>mage/translate.js</script></action>
                <action method="addJs"><script>lib/ccard.js</script></action>
                <action method="addJs"><script>prototype/validation.js</script></action>
                <action method="addJs"><script>varien/js.js</script></action>

                <action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
                <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action>
                <action method="addCss"><stylesheet>css/widgets.css</stylesheet></action>
                <action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action>

                <action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action>
                <action method="addItem"><type>skin_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action>

            </block>

            <block type="core/text_list" name="content" as="content" translate="label">
                <label>Main Content Area</label>
            </block>

        </block>
    </print>

但我得到的只是一个空白页面。请指教!

2 个答案:

答案 0 :(得分:0)

你得到一个空白页面是正确的,因为你没有更新块/引用中的内容,但是你要覆盖它。

如果您只是想添加一个额外的CSS文件,您应该这样做:

    <print translate="label" module="page">
        <reference name="head">
            <action method="addCss" name="global">
                <stylesheet>css/global.css</stylesheet>
            </action>
        </reference>
    </print>

否则,您可以复制并粘贴第二个代码段,添加包含CSS文件的行。

希望它会对你有所帮助!

答案 1 :(得分:-1)

您可以在page.xml标记中看到您粘贴了如何指定打印样式表:您需要在样式表上指定media属性,让浏览器在打印视图中应用它。您还需要针对所有页面定位要在<sales_order_print><default>上嵌入的页面的句柄,并在local.xml中将新样式表添加到<reference name="head">的右侧块:

<sales_order_print>
    <reference name="head">
        <action method="addCss">
            <stylesheet>css/custom.css</stylesheet>
            <params>media="print"</params>
        </action>
    </reference>
</sales_order_print>