I have created a template for Joomla 2.5, now I would like to create several variations of the same template which have different colors. I would like to select in the template settings which color the template should use.
How can I do that?
To add parameters in your template, you firstly need to add the following code to your templateDetails.xml file:
<config>
<fields name="params">
<fieldset name="advanced">
<field name="template_colour" type="list" default="default" label="Colour" description="">
<option value="black">Black</option>
<option value="red">Red</option>
<option value="green">Green</option>
</field>
</fieldset>
</fields>
</config>
Once done, upload your CSS files to the template folder and give them specific names which are the same as your option values, such as green.css
, red.css
and black.css
.
Then, open you index.php file and search for the code that is beimg used to import the CSS file. You can then add in the following code:
<?php
$colour = $this->params->get('template_colour', 'black') // black is the default
$doc = JFactory::getDocument();
$doc->addStyleSheet(JUri::root () . 'templates/' . $this->template . '/css/'. $colour.'.css');
?>
What this does it, is get the colour value and applies it which then imports that specific colour css file
Hope this helps