Thursday, June 15, 2006

Joomla: Include PHP scripts on content pages

Joomla CMS LogoJoomla, derived from the popular Mambo, is a fully fledged open-source content management system based on PHP and MySQL. And despite its flexibility and powerful administration, it is a setup nightmare for the average webmaster.

Unlike pseudo-CMS solutions like Postnuke, it is geared towards larger projects and does not allow "Hack and Slash" PHP code to be inserted into content pages on-the-fly. Joomla does include a wrapper module which allows for the inclusion of "foreign" content originating from other websites - but only via the use of iFrames. Out of the box, Joomla cannot include PHP scripts like forums on content pages.

The options are limited to
- writing your own component/module,
- hacking the Joomla core or
- installing a mod.

If it was a larger project, a dedicated component for each use would be a viable solution. Hacking the CMS core to allow the integration of PHP code is a very bad idea on the other side because of future compatibility problems.
A mod to distinguish PHP code from actual content is usually the best idea.

kl_php listens for signal words in the actual content fields and processes anything in between {kl_php} brackets as PHP.
You can download it and install it straight from the ZIP file via the admin interface:
Install New Mambots

After the installation, you have to activate (publish) the mambot.
Install New Mambots
kl_php has to be the first Mambot in order or the PHP output will come up be above or below the actual content. Parameters can be set according to personal preference.

From now on, you can include PHP code on Joomla pages using
{kl_php}
include("php_file.php");
{/kl_php}

The mod can also be used to catch and process form input via PHP as explained over at MamboServer.com.

Furthermore you should deactivate the Joomla WYSIWYG editor when including PHP code because HTML entities can cause problems.

0 Comments:

Post a Comment

<< Home

 
eXTReMe Tracker