简体   繁体   English

如何在JOOMLA中获取头部数据?

[英]How to get head data in JOOMLA?

Is there any method to get the <head></head/> data from html ? 有什么方法可以从html获取<head></head/>数据吗? I found only getHead() , but it return array of elements. 我发现只有getHead() ,但是它返回元素数组。 The problem is that i need to check if one of my js scripts is already included. 问题是我需要检查是否已经包含我的js脚本之一。 It has a keyword in the name, but i don't have a full path to it. 它的名称中有一个关键字,但是我没有完整的路径。

you can try find you script in JDocument object: 您可以尝试在JDocument对象中找到脚本:

$doc = JFactory::getDocument();
print_r($doc->_scripts);

It contain array with already added scripts, where the key is a script path. 它包含具有已添加脚本的数组,其中键是脚本路径。 Of course it works only if the script added using $doc->addScriptDeclaration(); 当然,只有在使用$doc->addScriptDeclaration();添加脚本的情况下,它才有效$doc->addScriptDeclaration();

There is also the JDocumentHTML::getHeadData() method to retrieve styles scripts and other things from the head as an array. 还有JDocumentHTML :: getHeadData()方法,可以从头开始以数组的形式检索样式脚本和其他内容。

For example I've used it to remove some weird empty link stylesheet files that were placed in the head but dunno where they came from: 例如,我已使用它删除了放置在头部但不知道它们来自何处的一些奇怪的空链接样式表文件:

// get current instance of Document object
$doc = JFactory::getDocument();

// get the head data (it's returned as an array)
$jhead = $doc->getHeadData();

// remove empty links
unset($jhead["styleSheets"][""]);

//set the new Head array data
$doc->setHeadData($jhead);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM