简体   繁体   English

手动控制 <head> Joomla的加价

[英]Manually control <head> markup in Joomla

Is there a way to manually configure the contents of the <head> section of the site in Joomla 3.1? 有没有办法在Joomla 3.1中手动配置站点的<head>部分的内容? I want to use the templating system for the entire markup of the page, including everything between <html></html> . 我想将模板系统用于整个页面标记,包括<html></html>之间的所有内容。

I just read this: http://forum.joomla.org/viewtopic.php?f=466&t=230787 and I am astonished at the response. 我刚刚读到这篇: http//forum.joomla.org/viewtopic.php?f = 466&t = 230787 ,我对这个回复感到惊讶。 Surely this is template/data separation 101. Has this been fixed in the latest Joomla release? 当然这是模板/数据分离101.这是在最新的Joomla版本中修复的吗?

If you are planning for a template development and you need all your template data get separated from Joomla libraries or core file (the head section). 如果您计划进行模板开发,则需要将所有模板数据与Joomla库或核心文件(头部)分开。

Normally the head section include will works like 通常头部包括将工作

<jdoc:include type="head" />

it loads the content from libraries libraries\\joomla\\document\\html\\renderer\\head.php 它从库libraries\\joomla\\document\\html\\renderer\\head.php加载内容

If you want to override the content of head you can make a module for your task. 如果要覆盖head的内容,可以为任务创建一个模块。 Just create a module and include that module instead of this head make sure that have all required codes added to work $document Class otherwise it miss a lot off features of Joomla regarding document class 只需创建一个模块并包含该模块而不是此头,确保添加所有必需的代码以工作$document Class否则它会错过Joomla关于document class的很多功能

As explained by the answer from Jobin, normally , you would include the head data by using the <jdoc:include type="head" /> tag, but if you want more control over this, you can use the JDocument . 正如Jobin的答案所解释的那样, 通常 ,您将使用<jdoc:include type="head" />标记包含头数据,但如果您想要对此进行更多控制,则可以使用JDocument

Example code in your template's PHP: 模板PHP中的示例代码:

$doc = JFactory::getDocument();
$my_head_data = $doc->getHeadData();

This will give you an array of the data that JDocument would normally print, so that you can completely choose what to print and how. 这将为您提供JDocument 通常打印的数据数组,以便您可以完全选择要打印的内容和方式。

To make jQuery load from CDN and get it on top of the script list, I made a little patch just after the $doc = JFactory::getDocument(); 为了从CDN加载jQuery并将其放在脚本列表之上,我在$ doc = JFactory :: getDocument()之后做了一个小补丁。 that manipulates the header array directly inside the $this object as follows: 它直接在$ this对象内操作头数组,如下所示:

$my_jquery    = "//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js";
$my_jquery_ui = "//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js";
$my_jquery_cx = $this->baseurl."/media/jui/js/jquery-noconflict.js ";

foreach($this->_scripts as $k=>$v) {
// put own jquery.conflict && jquery-ui && jquery on top of list
    if( strpos($k,'jquery.min.js')) {
        unset($this->_scripts[$k]);

        $r = array( $my_jquery_cx => $v);
        $this->_scripts = $r + $this->_scripts;

        $r = array( $my_jquery_ui => $v);
        $this->_scripts = $r + $this->_scripts;

        $r = array( $my_jquery => $v);
        $this->_scripts = $r + $this->_scripts;
    }
    else if( strpos($k,'jquery.ui.min.js')) {
        unset($this->_scripts[$k]);
    }
    else if( strpos($k,'jquery-noconflict.js')) {
        unset($this->_scripts[$k]);
    }
}

Replace $my_jquery_xxx with editable config parameters in your templateDetails.xml file 使用templateDetails.xml文件中的可编辑配置参数替换$ my_jquery_xxx

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

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