4

Is there a way to manually configure the contents of the <head> section of the site in Joomla 3.1? I want to use the templating system for the entire markup of the page, including everything between <html></html>.

I just read this: http://forum.joomla.org/viewtopic.php?f=466&t=230787 and I am astonished at the response. Surely this is template/data separation 101. Has this been fixed in the latest Joomla release?

Flash
  • 15,945
  • 13
  • 70
  • 98
  • What exactly are you trying to do? Chances are that these files have been re-written more than 2 times since the topic you posted (from 2007!) was created. – mavrosxristoforos Nov 01 '13 at 05:49
  • I want control over the HTML markup of all my pages, and specifically Joomla does not appear to provide this for the `head` section without core hacks. Meta tags, stylesheets, scripts etc. – Flash Nov 01 '13 at 06:58
  • Where is your code running? From a template or some other extension? – mavrosxristoforos Nov 01 '13 at 06:59
  • The rest of my page is built based on a template which I wrote - but `` spits out a bunch of stuff I don't want. – Flash Nov 01 '13 at 07:00
  • The reason why Joomla use `` is, it grabs all the content specified for the `` and combines it into one. There are a lot of extensions that will need to include Javascript for example in the head using the `JHtml()` or `$doc->addScript()`. It simply makes life a lot easier. – Lodder Nov 01 '13 at 09:01

3 Answers3

3

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).

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

If you want to override the content of head you can make a module for your task. 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

Jobin
  • 8,238
  • 1
  • 33
  • 52
  • Thanks - can you please explain your last sentence in more detail? Are there other side effects if I leave `` out entirely? – Flash Nov 01 '13 at 06:33
  • yes bcoz many components,modules,plugins etc are using document class for adding their style sheets scripts etc to the head section its rendering with this class – Jobin Nov 01 '13 at 08:40
0

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.

Example code in your template's 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.

mavrosxristoforos
  • 3,573
  • 2
  • 25
  • 40
0

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(); that manipulates the header array directly inside the $this object as follows:

$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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
19cool53
  • 1
  • 1