?
avatar brianteeman
brianteeman
11 Apr 2021

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
}
avatar brianteeman brianteeman - open - 11 Apr 2021
avatar joomla-cms-bot joomla-cms-bot - change - 11 Apr 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 11 Apr 2021
avatar dgrammatiko
dgrammatiko - comment - 11 Apr 2021

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

avatar brianteeman
brianteeman - comment - 11 Apr 2021

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.

avatar dgrammatiko
dgrammatiko - comment - 11 Apr 2021

It's a little more complicated. the ?template=foo is working because there is code to support it here:

$template = $filter->clean($params['template'], 'cmd');

but there is no such code for the styles. Also, styles are stored in the db so there's a need for a db query to set the styles to another Id.

avatar brianteeman
brianteeman - comment - 11 Apr 2021

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

avatar Fedik
Fedik - comment - 11 Apr 2021

it a bit tricky, you have 2 option:

  1. change input templateStyle in onAfterRoute: $app->input->set('templateStyle', 10);
  2. set your own template and its params 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);
avatar brianteeman brianteeman - change - 11 Apr 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-04-11 16:51:55
Closed_By brianteeman
avatar brianteeman brianteeman - close - 11 Apr 2021
avatar brianteeman
brianteeman - comment - 11 Apr 2021

thank you

avatar brianteeman
brianteeman - comment - 11 Apr 2021

I have it working as a plugin - just can't get it to work directly in the template php - guess thats not possible

avatar Fedik
Fedik - comment - 11 Apr 2021

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.

Add a Comment

Login with GitHub to post a comment