magento 在全站或者某页面增加外联js或者css的方法
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的方法的更多相关文章
- MVC学习随笔----如何在页面中添加JS和CSS文件
http://blog.csdn.net/xxjoy_777/article/details/39050011 1.如何在页面中添加Js和CSS文件. 我们只需要在模板页中添加JS和CSS文件,然后子 ...
- NFinal中增加生成页面自动带入js和css
增加在WebCompiler.aspx页面中的application.CreateCompile(true);方法里. //写aspx页面的自动提示层 #region 插入js&css com ...
- 页面渲染时js阻塞的解决方法
一般地,一个包含外部样式表文件和外部脚本文件的HTML载入和渲染过程是这样的: 浏览器下载HTML文件并开始解析DOM. 遇到样式表文件link[rel=stylesheet]时,将其加入资源文件下载 ...
- 页面中引入js的几种方法
通常大家最为熟悉的是一下两种方法: 在页面中直接写入<script type="text/javascript">js代码</script>. 在页面中引入 ...
- nuxt 头部引入js文件 第一次进入页面不加载js文件的解决方法
head () { return { title: '', meta: [ { hid: 'description', name: 'description', content: '' } ], sc ...
- 页面自动执行js的3种方法
1.最简单的调用方式,直接写到html的body标签里面: <html> <body onload="load();"> </body> & ...
- CSS补充之--页面布局、js补充,dom补充
CSS补充之--页面布局 主站一:(下面是一个大致的模板) <div class="pg-header"> <div style="width: 120 ...
- Vue2之页面 、js 、css分离
在编写vue的时候,页面数据少的时候,可以将所有的js和css都可以直接写在页面上,但是页面数据多,js.css的方法和样式多的时候,都放在一个页面的时候,就显得页面vue十分的臃肿. 所以写项目的时 ...
- 在 Students 的 Index 页面增加列标题链接(排序),分页,过滤和分组功能
3-1 在 Students 的 Index 页面增加列标题链接 为 Index 页面增加排序的功能,我们需要修改 Student 控制器的 Index 方法,还需要为 Student 视图增加代码 ...
随机推荐
- poj2594——最小路径覆盖
Description Have you ever read any book about treasure exploration? Have you ever see any film about ...
- RMAN异机恢复实验---转载
一.RMAN异机恢复实验 2011年3月23日00:44 1.环境介绍: 主机1: 操作系统 REDHAT5.5 IP地址 172.16.1.120 主机名 sigle 数据库版本 10.2.0.4 ...
- tarjan用法——割点
今天洛谷疯狂给我推送tarjan的题(它好像发现了我最近学tarjan),我正好做一做试一试(顺便练一练快读和宏定义). 其实找割点的tarjan和算强连通分量的tarjan不一样,找割点的判定条件比 ...
- Java 发送短信
这是一个调用sms接口发短信的程序,支持同时发送的短信量并不是很大,只作为学习使用(当然如果你想内部使用也行) 源码:package com; import org.apache.commons.ht ...
- Django day07 (二)单表操作
单表操作 -mysql数据库:settings里配置: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME ...
- # 深入理解Redis(二)——内存管理的建议与技巧
引语 随着使用Redis的深入,我们不可避免的需要深入了解优化Redis的内存,本章将重点讲解Redis的内存优化之道,同时推荐大家阅读memory-optimization一文. 想要高效的使用Re ...
- A - Fox And Snake
Problem description Fox Ciel starts to learn programming. The first task is drawing a fox! However, ...
- .net core2.0 读取appsettings.json
一.在start.up中添加注入 二.使用
- SQLServer外部数据导入--Excel版
例如要在test表里插入多行数据 假设字段有: ID.Name 首先要有需要导入的数据的Excel A1 对应ID B1 对应Name 选中Excel第一行的空白处,比如C1,在工具栏的函数文本框里输 ...
- CSS浮动的处理
之前已经发过一遍有关浮动的解决办法,今天看到一些资料后又有了新的想法: 在CSS布局中float属性经常会被用到,但使用float属性后会使其在普通流中脱离父容器,让人很苦恼 1 浮动带来布局的便利, ...