【发布时间】:2014-03-24 13:28:02
【问题描述】:
我正在尝试通过我的 xml 文件将我的链接添加到 head 部分,但没有任何反应(magento 1.7.0.2)
<action method="addLinkRel"><rel>canonical</rel><href>http://fonts.googleapis.com/css?family=Dancing+Script</href></action>
请说出正确的方法。
【问题讨论】:
我正在尝试通过我的 xml 文件将我的链接添加到 head 部分,但没有任何反应(magento 1.7.0.2)
<action method="addLinkRel"><rel>canonical</rel><href>http://fonts.googleapis.com/css?family=Dancing+Script</href></action>
请说出正确的方法。
【问题讨论】:
可能是这样,显示完整的布局 XML 结构:
<?xml version="1.0"?>
<layout>
<default>
<reference name="head">
<block type="core/text" name="any.name.here">
<action method="setText"><text><![CDATA[<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Dancing+Script">]]></text></action>
</block>
</reference>
</default>
</layout>
setText 让您几乎可以做任何事情,并且对于任何第三方 js 或 css 来说都是一个安全的选择。
【讨论】:
<rel>canonical</rel> 用于向头部添加规范链接。
要添加样式表,请使用:
<reference name="head">
<action method="addLinkRel">
<rel>stylesheet</rel>
<href>http://fonts.googleapis.com/css?family=Dancing+Script</href>
</action>
</reference>
【讨论】:
<rel> 标签中更改它,现在工作正常,
你用过<reference>吗?
<reference name="head">
<action method="addLinkRel">
<rel>canonical</rel>
<href>http://fonts.googleapis.com/css?family=Dancing+Script</href>
</action>
</reference>
也可以查看link
【讨论】:
<reference name="head"> 标记中添加了我的 <action>,现在它可以工作了。我在<rel> 之后缺少<href> 标记以提供链接。
在我的代码中,我通常将它作为一个块插入。见下面 google_font_material_icons 之一:
<layout version="0.1.0">
<default translate="label" module="page">
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
<block type="page/html_head" name="head" as="head">
<action method="addCss"><stylesheet>css/style.css</stylesheet><params>media=screen,projection"</params></action>
<block type="core/text" name="google_font_material_icons">
<action method="setText"><text><![CDATA[<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/icon?family=Material+Icons">]]></text></action>
</block>
</block>
....
希望对你有帮助。
【讨论】: