Header

How to customise a Joomla template based on article ID

Working on a custom Joomla template, I needed to change the page layout for a specific article and creating a new template for this one article didn't seem to be the right tool for the job.

The solution was suprisingly easy.

customise template based on article id

 

In the head of your template index.php file,  use JFactory to grab the article ID

$id = JFactory::getApplication()->input->getInt('id');

Then use this $id in the logic of your template file to manipulate the output. For me it was something like:

...
if ($id == 46){ // the ID of the page I wanted to customise

// add your logic here

}
...

That's it, it worked like a charm for me and didn't introduce the overhead of installing a second custom template for this one article.

 

Pas de connexion Internet