Magento 1.X 到Magento 2.X在模板静态文件引用上的差别

3,795 人次阅读
一条评论

共计 1549 个字符,预计需要花费 4 分钟才能阅读完成。

特大利好消息:现在已经可以用相同的接口来访问Skin和Library文件了。所以,现在你再也不用在head block中引用这些文件前去分辨他们了!因此,为了能够使用特定的addCss和addJs特性方法,\Magento\Page\Block\Html\Head::addItem这种型式已经被抛弃了。

 Change  Was in Magento 1.x Became in Magento 2.x
 RSS Layout Instruction

[php]<reference name="head">
<action method="addItem">
<type>rss</type>
<file>feed.xml</file>
<title>RSS Feed</title>
</method>
</reference>[/php]

[php]<reference name="head"> <action method="addRss"> <title>RSS Feed</title> <file>feed.xml</file> </method> </reference>[/php]

 CSS Layout Instruction

[php]<reference name="head">
<action method="addItem">
<type>js_css</type>
<file>style.css</file>
</method>
<action method="addItem">
<type>skin_css</type>
<file>style.css</file>
</method>
</reference>[/php]

[php]<reference name="head">
<action method="addCss">
<file>style.css</file>
</method>
</reference>[/php]

 JavaScript Layout Instructions

[php]<reference name="head">
<action method="addItem">
<type>js</type>
<file>script.js</file>
</method>
<action method="addItem">
<type>skin_js</type>
<file>script.js</file>
</method>
</reference>[/php]

[php] <reference name="head">
<action method="addJs">
<file>script.js</file>
</method>
</reference>[/php]

 RSS PHP Call

[php]$headBlock->addItem(
‘rss’,
‘feed.xml’,
‘title="RSS Feed"’
);[/php]

[php]$headBlock->addRss(
‘RSS Feed’,
‘feed.xml’
)[/php]

 CSS PHP Call

[php]$headBlock->addItem(
‘js_css’,
‘style.css’
);
$headBlock->addItem(
‘skin_css’,
‘style.css’
)[/php]

[php]$headBlock->addCss(‘style.css’)[/php]

 JavaScript PHP Call

[php]$headBlock->addItem(
‘js’,
‘script.js’
);
$headBlock->addItem(
‘skin_js’,
‘script.js’
)[/php]

[php]$headBlock->addJs(‘script.js’)[/php]

各位,准备好Magento 2的到来吧!

正文完
 0
评论(一条评论)