1,在整站末尾增加外联资源

  找到当前主题的布局文件cms.xml,在<default></default>添加如下代码:

        <reference name="before_body_end">
<!-- add another block of type page/html_head to have all the great functionality to add/remove css and js stuff -->
<!-- it is important to set your own template, because the head block has a defined default template page/head.phtml which has all the stuff of the head. Using this will bring a lot of problems -->
<block type="page/html_head" name="scripts_in_footer" template="country/scriptscss.phtml">
<!-- add whatever you want as you are used to in the head via the standard magento api -->
<action method="addItem"><type>skin_js</type><name>country/country.js</name></action>
</block>
</reference>

2,在某个页面添加外联资源

  找到当前页对应moudel的layout文件,在对应控制器中添加上述代码:

  

    <country_index_index>

        <reference name="before_body_end">
<!-- add another block of type page/html_head to have all the great functionality to add/remove css and js stuff -->
<!-- it is important to set your own template, because the head block has a defined default template page/head.phtml which has all the stuff of the head. Using this will bring a lot of problems -->
<block type="page/html_head" name="scripts_in_footer" template="country/scriptscss.phtml">
<!-- add whatever you want as you are used to in the head via the standard magento api -->
<action method="addItem"><type>skin_js</type><name>country/country.js</name></action>
</block>
</reference> </country_index_index>

3,新建template文件scriptscss.phtml,添加如下代码

  

<?php // and to echo the whole stuff later in the template, you need to add the code, so the added js/Css files are echoed ?>
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>

刷新页面,加载完成,主要涉及的是before_body_end块定义加载的位置,使用html_head块里面的方法添加资源到对应的页面上,

magento 在全站或者某页面增加外联js或者css的方法的更多相关文章

  1. MVC学习随笔----如何在页面中添加JS和CSS文件

    http://blog.csdn.net/xxjoy_777/article/details/39050011 1.如何在页面中添加Js和CSS文件. 我们只需要在模板页中添加JS和CSS文件,然后子 ...

  2. NFinal中增加生成页面自动带入js和css

    增加在WebCompiler.aspx页面中的application.CreateCompile(true);方法里. //写aspx页面的自动提示层 #region 插入js&css com ...

  3. 页面渲染时js阻塞的解决方法

    一般地,一个包含外部样式表文件和外部脚本文件的HTML载入和渲染过程是这样的: 浏览器下载HTML文件并开始解析DOM. 遇到样式表文件link[rel=stylesheet]时,将其加入资源文件下载 ...

  4. 页面中引入js的几种方法

    通常大家最为熟悉的是一下两种方法: 在页面中直接写入<script type="text/javascript">js代码</script>. 在页面中引入 ...

  5. nuxt 头部引入js文件 第一次进入页面不加载js文件的解决方法

    head () { return { title: '', meta: [ { hid: 'description', name: 'description', content: '' } ], sc ...

  6. 页面自动执行js的3种方法

    1.最简单的调用方式,直接写到html的body标签里面:   <html> <body onload="load();"> </body> & ...

  7. CSS补充之--页面布局、js补充,dom补充

    CSS补充之--页面布局 主站一:(下面是一个大致的模板) <div class="pg-header"> <div style="width: 120 ...

  8. Vue2之页面 、js 、css分离

    在编写vue的时候,页面数据少的时候,可以将所有的js和css都可以直接写在页面上,但是页面数据多,js.css的方法和样式多的时候,都放在一个页面的时候,就显得页面vue十分的臃肿. 所以写项目的时 ...

  9. 在 Students 的 Index 页面增加列标题链接(排序),分页,过滤和分组功能

    3-1  在 Students 的 Index 页面增加列标题链接 为 Index 页面增加排序的功能,我们需要修改 Student 控制器的 Index 方法,还需要为 Student 视图增加代码 ...

随机推荐

  1. 的Linq未提交之前插入/修改时重新查询不准确问题

    来园子已经两年了,每次都是看,这次咱也写一次. 说一下今天遇到的Linq问题: 每一次插入流水表时,都需要查找表中最大的流水号+1,并且将该流水号返回,但是在同一个SubmitChange之内插入多条 ...

  2. 解决WinForm下ListBox控件“设置DataSource属性后无法修改项集合”

    解决WinForm下ListBox控件“设置DataSource属性后无法修改项集合” 最近更新: 2013-2-15    587   很少写WinForm程序第一次使用ListBox控件就遇到了比 ...

  3. Codeforces--630E--A rectangle(规律)

     E - A rectangle Crawling in process... Crawling failed Time Limit:500MS     Memory Limit:65536KB  ...

  4. C语言程序判断文件夹是否存在

    #include <stdio.h> #include <io.h> int main(void){ if ( !access("C://Users/hui" ...

  5. Python 38 注册和修改密码

    一:注册系统服务 1.添加环境变量:桌面点击我的电脑------>右键属性------>双击高级系统设置------>点击环境变量------>找到在系统变量中的Path后双击 ...

  6. Nginx代理配置-centos6.10版

    nginx代理配置 cd /etc/nginx/init.d vi default.conf 添加: upstream server1{ server 192.168.125.128:8100 wei ...

  7. Promise-js异步加载解决方案

    范例: var p = new Promise(function(resolve, reject){ //做一些异步操作 setTimeout(function(){ console.log('执行完 ...

  8. office 2010 破解

    使用Rearm命令激活延迟重置Office 20101.安装Offcie 2010 安装Offcie 2010,默认30天的试用期,这里要注意,上文提供的Office 2010是零售版,所以没有序列号 ...

  9. struts2OGNL表达式(三)

    OGNL表达式 OGNL对象试图导航语言.${user.addr.name}这种写法就叫对象试图导航.Struts框架使用OGNL作为默认的表达式语言 OGNL不仅仅可以试图导航,支持比EL表达式更加 ...

  10. GitHub上fork别人打代码后如何保持和原作者同步的更新

    1.进入你的GitHub发起Pull  request 2.选择compare across  forks 3.反向操作.base fork改为自己的,head fork改为原作者的 4.点击 cre ...