24

I'm writing a component and would like to insert images from the template folder.

How do you get the correct path to the template folder?

Alex Bogias
  • 1,826
  • 2
  • 30
  • 45
nickf
  • 537,072
  • 198
  • 649
  • 721

3 Answers3

34

IIRC, the $mainframe global object is eventually going away. Here is a way to do it through the framework:

$app = JFactory::getApplication();
$templateDir = JURI::base() . 'templates/' . $app->getTemplate();
jlleblanc
  • 3,510
  • 25
  • 26
6

What kind of path... On filesystem:

$templateDir = JPATH_THEMES.DS.JFactory::getApplication()->getTemplate().DS;
Peter Ajtai
  • 56,972
  • 13
  • 121
  • 140
Alexey Sviridov
  • 3,360
  • 28
  • 33
3

I've figured out one method. Use the global $mainframe object.

$templateDir = $mainframe->getBasePath() . "templates/" . $mainframe->getTemplate();

Is there another (better) way?

nickf
  • 537,072
  • 198
  • 649
  • 721