4

I've created a Joomla 3 template. When I install the template, I'd like to have the template images automatically install into the joomlaroot/images location. The reason I'd like to do this is because several templates will share the same images. I know I can manually put the images in whatever folder I like, but I'd prefer to have it done automatically when I install the template.

  • Is it possible to have a templates images automatically install to the joomlaroot/images directory? If yes, how can I do it?
  • If no, are there any alternative ways of achieving the same thing?
3

Basically, you could use an installer script, and create/copy the files after installation. The problem is that AFAIK templates does not trigger the script.

I suggest you create a package, and then include your template there, because the package installer should call the installer script.

Then create your postflight script by adding this to your XML file:

<scriptfile>script.php</scriptfile>

And somthing like this in the script.php file (not tested):

<?php

defined('_JEXEC') or die('Restricted access');

class pkg_helloWorldInstallerScript {

    function install($parent) {

        jimport('joomla.filesystem.folder');
        jimport('joomla.filesystem.file');

        //change this to the name of the folder you want to create
        $newfolder = 'myfolder';

        if(JFolder::create(JUri::root() . 'images/' . $newfolder)) {        
            //duplicate the line below as many times as you want for each file you want to move
            JFile::move(JUri::root() . 'templates/TEMPLATENAME/images/image.png', JUri::root() . 'images/' . $newfolder);
        }
    }
}    
?>

Original code by @Lodder

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.