Making single installation packages for Joomla! 1.5 and 2.5 series

From Joomla! Documentation

Revision as of 03:29, 17 July 2011 by Nikosdion (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Documentation all together tranparent small.png
Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by Nikosdion (talk| contribs) 4 years ago. (Purge)

It is possible to create a single installation package which can install a component in Joomla! 1.5, 1.6 and 1.7 with minor changes. Below you will find some of the most common tricks required to create an extension which is compatible with all current versions of the Joomla! CMS.

Dealing with API changes

You will regularly bump into cases where an API has changed between Joomla! 1.5, 1.6 and 1.7. In order to cater for them, you need to run slightly different code based on the Joomla! version. Right now it's possible to do that by writing conditional statements like this:

if(version_compare(JVERSION,'1.7.0','ge') {
// Joomla! 1.7 code here
} elseif(version_compare(JVERSION,'1.6.0','ge') {
// Joomla! 1.6 code here
} else {
// Joomla! 1.5 code here

If you do not have Joomla! 1.7-specific code -i.e it is the same as the Joomla! 1.6-specific code- please use the following code:

if(version_compare(JVERSION,'1.6.0','ge') {
// Joomla! 1.6 code here
} else {
// Joomla! 1.5 code here

While this conditional statement looks like an overkill, it has two major advantages:

  • Compatibility with all Joomla! versions using the same package, therefore using the same codebase, ergo less maintenance overhead
  • Once, let's say, Joomla! 1.8 is released and you decide to drop support for earlier Joomla! releases, we can just search your code for "if(version_compare(JVERSION," and remove all of the legacy code.

One XML configuration file, multiple Joomla! versions

Various XML files in Joomla! accept settings, or parameters. For example your extension manifest file, the config.xml file and the view XML files all accept such settings. You may have noticed that whereas in Joomla! 1.5 these were found under the <params> tags, in Joomla! 1.6 and later they are found inside <filedsets>. One hidden secret of Joomla! is that Joomla! 1.5 will ignore Joomla! 1.6 syntax, whereas Joomla! 1.6/1.7 will ignore Joomla! 1.5 syntax. This allows you to have a single XML file which caters for all Joomla! releases. For example, here's a sample config.xml file, to be placed in the component's backend directory:

<?xml version="1.0" encoding="utf-8"?>
		<!-- Joomla! 1.5 uses params -->
		<param name="foobar" type="text" default="" size="30"
			description ="COM_FOOBAR_OPTION_FOOBAR_DESC" />
		<!-- Joomla! 1.6 uses fieldset -->
		<field name="foobar" type="text" default="" size="30"
			description ="COM_FOOBAR_OPTION_FOOBAR_DESC" />

That's how easy it is! Bonus tip: take a look at how the translation keys are named in this example. It's advisable -albeit not required- to follow a hierarchical approach to your translation keys. It might sound like OCD, but it helps your translators by providing context and you to debug language related issues.