?
avatar lucianito20012000
lucianito20012000
10 Oct 2014

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.

Expected result

I propose to modify setTemplate() adding the id of the template as an argument.

The questions are:

  1. Is there any other way (unknown by VM -and by me- ) to re-set the template including the template id in the object?

  2. 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);
}
}
}

avatar lucianito20012000 lucianito20012000 - open - 10 Oct 2014
avatar Bakual
Bakual - comment - 10 Oct 2014

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 with setTemplate().

I think adding id (and home) as arguments to this method would actually be wrong. We would rather need a setTemplateStyle() method where you can pass the id. :smile:

avatar atpatil11
atpatil11 - comment - 18 Oct 2014

@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.

avatar brianteeman brianteeman - change - 3 Jan 2015
Labels Added: ?
avatar brianteeman brianteeman - change - 3 Jan 2015
Labels Added: ?
avatar vdespa
vdespa - comment - 12 May 2015

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!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4503.

avatar zero-24 zero-24 - change - 12 May 2015
Title
Template id is not present in setTemplate()
Template id is not present in setTemplate()
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-05-12 20:33:07
Closed_By zero-24
avatar zero-24 zero-24 - close - 12 May 2015
avatar RaimisErvit
RaimisErvit - comment - 14 Sep 2017

Maybe on 3.7 work setTemplateStyle() or other sets where can set template ID ?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/4503.

Add a Comment

Login with GitHub to post a comment