?
Referenced as Pull Request for: # 8611
avatar AndyTheFactory
AndyTheFactory
6 Dec 2015

Steps to reproduce the issue

$app = JFactory::getApplication();
    $t=$app->getTemplate(true);
    var_dump($t);

results in
object(stdClass)#582 (4) {
** ["id"]=>
string(2) "7"
["home"]=>
string(1) "1"**
["template"]=>
string(10) "protostar"
["params"]=>
object[....]
}

But after a setTemplate, the same call has a different type of result

$app = JFactory::getApplication();
$app->setTemplate('beez3',null);
    $t=$app->getTemplate(true);

results in
object(stdClass)#865 (2) {
["template"]=>
string(10) "rt_anacron"
["params"]=>
..........
}

The previous bolded properties are missing. This leads for instance to some notices in virtuemart+gantry templates

Expected result

The getTemplate(true) call should always return the same type of class

Actual result

The getTemplate(true) call should returns different

System information (as much as possible)

Joomla 3.4.5

Additional comments

The problem is that
public function setTemplate($template, $styleParams = null)
Sets just some part of the JApplicationSite::template class and does not get the id and home from the #__template_styles

The problem is that you could have more then one records in #__template_styles with the same template name
a quick fix would be to add the missing properties with value null.

avatar AndyTheFactory AndyTheFactory - open - 6 Dec 2015
avatar Bakual
Bakual - comment - 6 Dec 2015

You identified the issue correctly. setTemplate does set the template without specifying a style.

You could set the style properties to null, or you could just check the presence of the property in your own code instead of just assuming they're always there.
Do you want to make a Pull Request?

avatar bertmert
bertmert - comment - 7 Dec 2015

To force the current style in too early requests i'm using something like this:

$actMenu = JFactory::getApplication()->getMenu()->getActive();
if (is_null($actMenu))
{
 $template_style_id = 0;
}
else
{
 $template_style_id = (int) $actMenu->template_style_id;
}
if ($template_style_id > 0)
{
 JTable::addIncludePath(JPATH_ADMINISTRATOR  .  '/components/com_templates/tables');
 $style = JTable::getInstance('Style', 'TemplatesTable');
 $style->load($template_style_id);
 if (!empty($style->template))
 {
  $app->setTemplate($style->template, $style->params);
 }
}
avatar AndyTheFactory
AndyTheFactory - comment - 7 Dec 2015

The problem is not getting my code to work :) that is easy. The problem is that there are template providers/frameworks like gantry that rely upon that consistency. I can "patch" them for my websites, but that is not a solution :D

I can make a pull request. The question is if i should go the "simple" route and just initialize the missing properties with null, or if I should try to guess the template_id for the template_name (this would be more rigurous)

avatar Bakual
Bakual - comment - 7 Dec 2015

You can't guess the template_id at all. In this cases, there is no style associated. The template is supposed to load with the parameters given in the call, or with its default values if no parameters are given.

avatar AndyTheFactory
AndyTheFactory - comment - 7 Dec 2015

Ok, did it on PR#8611

avatar AndyTheFactory AndyTheFactory - change - 7 Dec 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-12-07 20:38:25
Closed_By AndyTheFactory
avatar AndyTheFactory AndyTheFactory - close - 7 Dec 2015

Add a Comment

Login with GitHub to post a comment