I can detect the active template style in a frontend template with
$app->getMenu()->getActive()->template_style_id;
This will return values of 0
if it is the default template style or the id
if a style has been assigned to the menu
But is there a way that I can change the templatestyle in the template when a condition is met
eg
$option = $app->input->getCmd('option', '');
if ($option == 'com_content') {
change the templatestyle to template_style_id=12
}
Labels |
Added:
?
|
I'm sure there must be a way to it now. It can be done in a plugin but I wanted to try and just do it in the template itself.
It's a little more complicated. the ?template=foo
is working because there is code to support it here:
Getting the style is the easy part and in my case I know what the id of the style is that I want to use
it a bit tricky, you have 2 option:
templateStyle
in onAfterRoute
: $app->input->set('templateStyle', 10)
;onAfterDispacth
, the params should be loaded from your Template Style:$template = ... some code to load template name and params
$app->set('theme', $template->template);
$app->set('themeParams', $template->params);
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-04-11 16:51:55 |
Closed_By | ⇒ | brianteeman |
thank you
I have it working as a plugin - just can't get it to work directly in the template php - guess thats not possible
just can't get it to work directly in the template php
you mean in template index.php/component.php?
well, yea, there it will not work, because the params (template style) loaded before this file executed.
Need to be a plugin.
Once #32710 is merged you could recreate an object for templateParams (basically the db values for the style) and call that function with the template name and the obj you just created