I have an extension having this lines of code:
$app = JFactory::getApplication();
$template = $app->getTemplate(true);
$style = $template->id; //I use the template id number in my extension
I used Virtue Mart to reproduce the error. VM has an option to pick the template you want to use in the store. It ignores the default template you select in the "template manager" and reset the template by which you choose. Something like this:
$query = 'SELECT template
,params
FROM #__template_styles
WHERE id
="'.$template.'" ';
[etc, etc]...
$res = $db->loadAssoc();
$registry = new JRegistry;
$registry->loadString($res['params']);
$template = $res['template']; //the name of the template
....[etc,etc]..
$app->setTemplate($template,$registry); //setTemplate() accepts 2 arguments: template (string) and the template style parameters (mixed).
In this point the element "id" (that I use in my extension) is missed.
I propose to modify setTemplate() adding the id of the template as an argument.
The questions are:
Is there any other way (unknown by VM -and by me- ) to re-set the template including the template id in the object?
should setTemplate() be changed like:
public function setTemplate($template, $styleParams=null, $id=null )
{
if (is_dir(JPATH_THEMES . '/' . $template)) {
$this->template = new stdClass();
$this->template->template = $template;
$this->template->id = $id;
if ($styleParams instanceof JRegistry) {
$this->template->params = $styleParams;
}
else {
$this->template->params = new JRegistry($styleParams);
}
}
}
@lucianito20012000 Thanks for clarification.
I can easily set the new template using setTemplate method by passing only id of the available template. I checked by adding the setTemplate snippet in third party extensions as well.
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4503.
Labels |
Added:
?
|
Labels |
Added:
?
|
There has been little activity on this issue, so I am closing it for the moment. If anybody objects, it can be reopened anytime. Thanks @all!
Title |
|
||||||
Status | New | ⇒ | Closed | ||||
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-05-12 20:33:07 | ||||
Closed_By | ⇒ | zero-24 |
Maybe on 3.7 work setTemplateStyle() or other sets where can set template ID ?
I run into the same issue some days ago as it also happens with the Advanced Template Manager from NoNumber. My template was reading the id but it was not present due to this.
After looking at it then, I didn't see an obvious way to solve it. Reason is that the
setTemplate()
method allows to set a template and pass the style parameters directly as an argument. Thus you don't necessary have a matching style id because the parameters may actually be different from any saved style.One a sidenote, the
home
property is missing as well if the template has been set withsetTemplate()
.I think adding
id
(andhome
) as arguments to this method would actually be wrong. We would rather need asetTemplateStyle()
method where you can pass the id.