Joomla load script in a specific page(特定页面中的 Joomla 加载脚本)
问题描述
我正在 Joomla 中创建一个网站,想知道是否有办法使用 php 在特定页面中加载特定脚本....
I'm creating a website in Joomla and wondering if there is a way to load a specific script in a specific page using php....
例如我想加载一个:<script src="sample.js"> 在关于我们将要使用的页面中
e.g. i want to load a :
<script src="sample.js"> in the about us page where it is going to be use
我想这样做的原因是,即使页面中没有使用它们,也不会将它们全部加载到头部部分,这会使页面变慢......
the reason why I wanted to do this is that instead of having them all load in head section even if it is not being use in the page makes page slower...
推荐答案
您是否尝试在内容项或组件中执行此操作?如果您尝试在组件中执行此操作,可以使用以下方法将 JavaScript 文件添加到 only 该页面的头部:
Are you trying to do this in a content item or a component? If you're trying to do it in a component, this is the way to add a JavaScript file to the head portion for only that page:
$document =& JFactory::getDocument();
$document->addScript(JURI::base() . 'path/to/sample.js');
如果您尝试在内容项中执行此操作,您很可能需要查找或构建一个内容插件来扫描指示 Joomla 运行上述代码的令牌.我在不久前建立的一个网站上做了这个.我设置了它,以便插件可以在内容项中搜索 {js sample.js} 之类的标签,提取文件名,将脚本添加到文档中,然后搜索并替换文章中的标签.
If you're trying to do this in a content item, you'll most likely need to find or build a content plugin to scan for a token that tells Joomla to run code like above. I did this on one of the sites I built a while back. I had it set so that a plugin would search for tags like {js sample.js} in content items, extract the file name, add the script to the document, then search and replace the tag out of the article.
这篇关于特定页面中的 Joomla 加载脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:特定页面中的 Joomla 加载脚本
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
