javascript 在 Magento 静态块中添加 <style> 和 <script>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18606738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add <style> and <script> in Magento static block
提问by hims056
I have a static block (Identifier is mega_menu
)
我有一个静态块(标识符是mega_menu
)
It has some code like this:
它有一些这样的代码:
<ul class="dropdown-menu" role="menu">
<li data-submenu-id="submenu-patas">
<div id="submenu-patas" class="popover">
<h3 class="popover-title">Patas</h3>
<div class="popover-content"><img src="img/patas.png"></div>
</div>
</li>
<li data-submenu-id="submenu-snub-nosed">
<div id="submenu-snub-nosed" class="popover">
<h3 class="popover-title">Golden Snub-Nosed</h3>
<div class="popover-content"><img src="img/snub-nosed.png"></div>
</div>
</li>
</ul>
In the normal html file (from where I got this code) there are some styles and it's references like this:
在普通的 html 文件中(从我得到这个代码的地方)有一些样式,它的引用是这样的:
<link href="css/bootstrap.css" rel="stylesheet"> --<--Reference
<style>
body {
padding-top: 60px;
}
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet"> --<--Reference
<style>
.navbar .popover {
width: 400px;
-webkit-border-top-left-radius: 0px;
-webkit-border-bottom-left-radius: 0px;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
overflow: hidden;
}
</style>
And also some scripts and it's references like this:
还有一些脚本和它的引用是这样的:
<script src="../jquery.menu-aim.js" type="text/javascript"></script> --<Reference
<script src="js/bootstrap.min.js" type="text/javascript"></script> --<--Reference
<script>
var $menu = $(".dropdown-menu");
.
.
.
$(document).click(function() {
// Simply hide the submenu on any click. Again, this is just a hacked
// together menu/submenu structure to show the use of jQuery-menu-aim.
$(".popover").css("display", "none");
$("a.maintainHover").removeClass("maintainHover");
});
</script>
So my question is:
所以我的问题是:
Can I these styles and scripts directly in static block?
If no how can I add these styles and script with work for particular static block (e.g. mega_menu
here)?
我可以直接在静态块中使用这些样式和脚本吗?
如果没有,我如何为特定的静态块(例如mega_menu
这里)添加这些样式和脚本?
PS: Magento noob here
PS:这里是 Magento 菜鸟
回答by Keyur Shah
call phtml file from static block
从静态块调用 phtml 文件
{{block type="core/template" template="page/html/YOUR_FILE_NAME.phtml"}}
and write your code in YOUR_FILE_NAME.phtml
并在 YOUR_FILE_NAME.phtml 中编写您的代码