I'm developing a custom form field for my template and I need to know the name of this template from inside this form field. While otherwise I would do a setQuery to look for client_id=0 and home="1", this case is different because you can edit template styles even if they're not set as default.

My guess is that I need to read the current URL, get the item id and do a setQuery on this one. For that I would probably have to do some Uri method I'm still looking for.

Any idea if there's a better way please?

2 Answers 2


You can get it from template field in the form.

if ($this->form)
    $template = $this->form->getValue('template');
  • Sweet! Even more handy and probably more appropriate. Thank you!
    – thednp
    Feb 15, 2021 at 7:44

Yea, like I've explained above this worked for me:

$id = Uri::getInstance()->getVar('id');
$query = Factory::getDbo()->setQuery("SELECT `template`, `params` FROM `#__template_styles` where `id` = '" . $id . "'");
$templateObject = $query->loadObject();

// usage
// get template name
$template = $templateObject->template;

// get template params
$templateParams = $templateObject->params;

But yet again, if you guys have a better idea, make sure to let it out. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.