在Joomla中添加页面特定的JavaScript或CSS [英] Add page-specific javascript or CSS in Joomla

查看:234
本文介绍了在Joomla中添加页面特定的JavaScript或CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将JavaScript或CSS文件仅包含在Joomla中的某个文章中?

How do you include a javascript or CSS file only on a certain article in Joomla?

我有一篇文章需要jQuery UI和相关主题。因为这不是在任何其他页面上使用,我只想要这篇特定的文章。在HTML中添加必要的< script> < link rel =stylesheet> 该文章不工作,因为它们在保存时被删除。

I have one article which requires the jQuery UI and associated theme. Since this isn't being used on any other pages, I only want it for this particular article. Adding in the necessary <script> and <link rel="stylesheet"> tags in the HTML of the article doesn't work, since they get stripped out when saved.

如果有一个方法包括某些文件,或停止剥离这些标签,

If there was a method to include certain files, or to stop the stripping of those tags, that'd be really good.

推荐答案

我最终创建了一个插件来为我所维护的网站执行此操作;我可以释放它的代码,但它很简单解释。您构建一个内容插件,搜索 {css path / to / a / css / file.css} 等标签,然后将这些文件添加到HTML < head> 。一旦你有你想要包括的CSS或JS文件的名称,这里是你用来获取它的标题中的代码:

I ended up creating a plugin to do this for a site I maintain; I may release the code for it, but it's pretty simple to explain. You build a content plugin that searches for tags like {css path/to/a/css/file.css}, strips them out, then adds the files to the HTML <head>. Once you have the name of the CSS or JS file you want to include, here is the code you use to get it in the header:

$document =& JFactory::getDocument();
$document->addStyleSheet(JURI::base() . 'path/to/style.css');
$document->addScript(JURI::base() . 'path/to/script.js');

这篇关于在Joomla中添加页面特定的JavaScript或CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆