How to get default site template name in Joomla 2.5

Retrieving Site Template name is relatively easy when you need it within a site component. This can be done by using getTemplate()function in the following example. But what if you need to get the name of a Site Template from Administrator component or a module?

One way to get a name of the default site template name in Joomla 2.5 is to use the following code:

$app = JFactory::getApplication();
$templateName = $app->getTemplate();

However you will get an admin template name if the above code is executed from admin site. I don't believe there is a function that can retrieve a site template name regardless where you call it from. But I did find a way to get default site template name from the admin site by using the following SQL query:

$db = JFactory::getDBO();
$query = "SELECT template FROM #__template_styles WHERE client_id = 0 AND home = 1";
$db->setQuery($query);
$defaultemplate = $db->loadResult();

I'll be interested to know if you know a better way to get a site template name from admin area. Please leave a comment if you do.

Comments   

vakis
# vakis 2013-05-08 22:19
I was looking for a solution too in order to avoid the sql query. I need the site template name in order to construct the path to it from inside a system plugin. :) Unfortunately I ended up with a similar 'paragraph' too..

if you find a better solution let me know too.
cheers

 

Would you like to contribute?



Free business joomla templates