I'm creating a template and here is my templateDetails.xml.

<extension version="3.4" type="template" client="site" method="upgrade">
    <copyright>Copyright © 2015 memyself.com</copyright>



I'm using the upgrade method so that all files will be overwritten when a new update is installed. But I don't want custom.css to be overwritten when user installing an update (only when updating not for first install), because custom.css contains custom user edited code.

Is it possible to do such that?

  • 2
    Maybe use some sort of a script.php like you would for other extension types and when updating, check to see if a custom.css exists. If not, then move it.
    – Lodder
    Oct 10 '15 at 10:32

Thought I'd expand on my comment.

You're firstly going to need to add an install-uninstall-update script file to your component. Have a read of the Joomla Documentation on how to do this.

Once you have implemented this, you're going to want to use the update function which will only execute this code when the user is updating the component.

Inside this function, you'll need to get the contents of the CSS file that already exists. If it contains content, you don't need to override it.

So, when you ship out your first release of the extension, be sure that the CSS file has no content in it, not even any comments. In the update zip (e.g v1.0.1), you need to move the CSS file from the CSS directory to somewhere else (perhaps a new directory called update_css).

The finally, the code:

function update($parent) 
    // Import dependencies
    JLoader::register('JFile', JPATH_LIBRARIES . '/joomla/filesystem/file.php');

    // Define the old CSS file path
    $old_css = JPATH_ROOT . '/components/com_mycomponent/css/custom.css';

    // Check if the file exists
    if (JFile::exists($old_css))
        // Get the contents of the file
        if (file_get_contents($old_css) != '')
            // Define the new CSS file path
            $new_css = JPATH_ROOT . '/components/com_mycomponent/update_css/custom.css';

            // Check if the file exists
            if (JFile::exists($new_css))
                // Move the file
                JFile::move($new_css, $old_css);

I've added a few checks in here, however you'll need to make some changes to cater for yourself.

Hope this helps


I don´t know how to solve your question but I would explain how I do it in my components.

I use css/style.css that have the style of the component and then I load theme/css/custom_style.css that overright style with the customer style.

For instance, in style.css I have:

.box-wrapper{backgound:#ffffff; padding:10px; border:1px solid #ccc}

If I want to change the box I won´t touch the style.css but custom_style.css


It will change the box but manteinig the original style.css

Of course I won´t distribute custom_style.css in the package.

  • Fair solution, but this means the user needs to manually create a CSS file and import it
    – Lodder
    Oct 13 '15 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.