1

I have a site that uses 2 template styles for 2 different domain names running on the same Joomla installation. (Both have the same root template.)

I'm creating a custom component and a specific task needs to display a view. I'm using parent::display() to switch the view.

The problem I'm running into is that Template A is the default template. When I run this task from a page on Template B, I get the desired results, but on Template A.

I need to get the desired results on the same template style as the one in use when the task is called.

How can I find out which style is active when the task is called? How can I set the correct style when I display the result?

Thanks in advance for any help. I'm stuck!

2

You can force the template style like this:

     $templateStyleId = 3; // set here the template style id
     $app = JFactory::getApplication();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables');
     $tmplStyle = JTable::getInstance('Style', 'TemplatesTable');
     $tmplStyle->load($templateStyleId);

     if (!empty($tmplStyle->template)){
        $app->setTemplate($tmplStyle->template, $tmplStyle->params);
     }
1

A friend pointed this out to me.

Template is set by the active menu item. If there is no active menu item, there's no active template, so it drops to default template.

In view.html.php for the view I was working with, I had a function to prepare the document. I had to add/tweak the following code:

protected function _prepareDocument()
    {
        $app   = JFactory::getApplication();
        $menus = $app->getMenu();
        $menu = $menus->getActive();
        // If the active menu item isn't set, we lose the template
        if (!$menu) {
        $menus->setActive(573);
        }
}

The active menu item id can be anything you need it to be. I created a menu item on a hidden menu to represent this (which means I can add modules, etc to the page as well) and then took the ID number from the menu manager in the admin area.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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