$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
The getTemplate(true) call should always return the same type of class
The getTemplate(true) call should returns different
Joomla 3.4.5
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.
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);
}
}
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)
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.
Ok, did it on PR#8611
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-12-07 20:38:25 |
Closed_By | ⇒ | AndyTheFactory |
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?