0

Can you help please?

I've build a simple module which displays two 'back to top of page' arrows, one bottom left and the other bottom right. It works well if inside an existing template module position or in the component area using {loadmodule mod_backtotop}. However, I want to be able to automatically display the module as soon as it's installed, either without the need for a module position or maybe create a new module position upon installation?

I hope this makes sense, I'm not sure if I've explained it well.

Any help gratefully received. Thanks in advance.

UPDATE:

Thanks to @Lodder this is the code I used. Hopefully this will help others.

    if (strtolower($type) === 'install') 
    {       
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);

        $fields = array(
            $db->quoteName('position') . ' = ' . $db->quote('backtotop'),
            $db->quoteName('showtitle') . ' = 0',
            $db->quoteName('published') . ' = 1'
        );

        $conditions = array(
            $db->quoteName('module') . ' = ' . $db->quote('mod_backtotop')
        );

        $query->update($db->quoteName('#__modules'))->set($fields)->where($conditions);

        $db->setQuery($query);   
        $db->execute();     
    }
  • 1
    You can use this as a starting point: joomla.stackexchange.com/a/4593/168 It's specifically for plugins, but you can adapt it for a module – Lodder Sep 20 at 17:40
  • Thank you @Lodder. I've used your link to automatically publish my module and assign it to position 'backtotop', it works perfectly. However, because the position 'backtotop' doesn't exist in my template how do I get the module to actually display/render please? I've seen examples of how to render modules but I'm not sure where the code should go. – JJBW Sep 20 at 20:19
  • Please update your original question with any updates – Lodder Sep 21 at 12:13
  • As you can see my module now automatically publishes, but, to finalise it and I've searched a lot for this but can't find a solution, is there a way to automatically make the module's 'Module Assignment' be 'On all pages' please? When it installs it defaults to 'No pages'. – JJBW Sep 21 at 12:47
  • I believe that will need to be done in a different database table. – Lodder Sep 22 at 10:04

Your Answer

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

Browse other questions tagged or ask your own question.