Joomla { } brackets implementation

1.3k Views Asked by At

I am very new to Joomla and few plugins in Joomla uses variables like with {} brackets. For example '{mosmap}' displays Google maps in Joomla. I want to know how it works so that I can customize the plugin for my requirements.

2

There are 2 best solutions below

0
On BEST ANSWER

{} in joomla, [] in wordpress, they are called replacement tags. I've never done Joomla pluggins although i did some modules and components but i did shorttags in Wordpress and my guess is they work the exact same way.

The engine, Joomla or Wordpress, detects {} or [] and parses the content into something that can be transfered to your pluggin and then your pluggin can act on it.

For example, in Wordpress:

[mytag id="6" image="blabla.jpg"]

Relays to my wordpress plugin as an array in my function like:

function mytag_plugin($data){
    var_dump($data);
}

array(2){
    [id] => (int)6,
    [image] => (string)"blabla.jpg",
}

I'll recommend reading http://docs.joomla.org/Plugin for more information on it...

0
On

{} tags are used in Joomla plugins as replacement tags. It works using regular expression matching and replacement. As an example we can see the code for load module plugin which uses {loadposition} as the replacement tag(You can find the full code at file is <Joomla_installation_folder>/plugins/content/loadmodule.php)

It works in the following manner-

// expression to search for
$regex = '/{loadposition\s*.*?}/i';
$pluginParams = new JParameter( $plugin->params );

// check whether plugin has been unpublished
if ( !$pluginParams->get( 'enabled', 1 ) ) {
    $row->text = preg_replace( $regex, '', $row->text );
return true;
}

// find all instances of plugin and put in $matches
preg_match_all( $regex, $row->text, $matches );

The above code is for Joomla 1.5. Joomla 1.7 uses same method with some differences, but you can find the exact code at (<Joomla_installation_folder>plugins/content/loadmodule/loadmodule.php within the onContentPrepare() function).