ToHeader Joomla plugin
Facts - Php
Friday, 08 August 2008 12:48

Why using this plugin

I have a couple of websites containing many forms. At the moment these forms use FacileForms but I would like to use more basic stuff, like javascript combined with Ajax calls.

The javascript/Ajax framework jQuery offers enough functionality to build my forms. So I would like to use jQuery from joomla 1.5.x. I did a search to see what plugins and modules are available. First I found the jxcore plugin. This is a system plugin that can be used from other plugins. I asked how to use this plugin but never got a reply. I guess that this plugin can only be used from joomla php code. This is not what I want, I want to call jQuery functions by typing javascript into the Joomla article content.

From the jQuery website I figured out that all I need is a plugin that can insert some custom javascript code into the html head tag of my joomla pages. I found another plugin that can do this: the Custom Head Tag plugin from www.joomler.net. In the plugin configuration you can enter jQuery javascript and you can include javascript files. In the plugin configuration you can also enter the id's of the articles, categories and sections in which javascript will be inserted into the html head tag. Like the jxcore plugin a system plugin: it can not be directly called from the content of a joomla article.

I tested the Custom Header Tag plugin and it indeed works with jQuery javascript. By calling jQuery from the plugin I was even able to do Ajax calls from Joomla.

I could do my coding with this plugin but what I really want is a plugin including jQuery scripts. Such a plugin would make my forms easier to administer. So I requested the author of the Custom Head Tag plugin to make the enhancement. But then I found out that what I had requested came down to coding a new plugin rather than making just a simple enhancement. So I wrote the plugin myself.

How to use the ToHeader Content Plugin

After installing the plugin it should be enabled first. Here is an example that can be copied and pasted into your Joomla article text. This example calls jQuery javascript. Paste the example as html code, do not use the WYSIWYG html editor for editing the article:

<toheader>
<script>
$(document).ready(function(){
$("a").click(function(event){
   event.preventDefault();
   alert("Thanks for visiting- babu!");
 });
});
</script>
 
<script src="jquery-1.2.6/dist/jquery.pack.js"/>
<style>
  p { font: italic; }
</style>
</toheader>

For the example above you also need to download jquery and install it in the root directory of your website. Don't forget to add an "index.html" in each subdirectory. Click on any link in the page containing the toheader-tag above to see the effect of the jQuery script. You should see an alert when clicking on a link.

The tags inside

toheader
 will be transferred to the html header.

To be more precisely: the code inside the

toheader
 tag will show up in the html code that corresponds to

<jdoc:include type="head" />

in your joomla template.

The ToHeader content plugin is not only suitable for using jQuery scripts in your Joomla website. It is also possible to use the ToHeader content plugin with similar javascript/Ajax frameworks such as the Dojo Toolkit. But to be honest, I have not tried using the Dojo Toolkit with the ToHeader plugin.

Everything comes at a price:

  • This plugin only works with PHP 5 and above.
  • This plugin only works with Joomla 1.5.x in native mode
  • Using an WYSIWYG HTML editor for editing pages containing this plugin is not recommended.
  • If you plan to write many pages using jQuery then you should consider combining the CustomHeaderTag plugin with the ToHeader Content plugin. The ToHeader Content plugin is can be used to include the jQuery core script (jquery-1.2.6/dist/jquery.pack.js in the example) and the ToHeader Content plugin will include your custom code. This will make upgrades of the jQuery package less time consuming.

Download the ToHeader Content Plugin

The plugin is released under the GNU/GPL license v2 and you can download it here: ToHeader Content Plugin

Last Updated ( Monday, 22 September 2008 11:05 )