contao/test — Issue #46: Organising templates in /templates folder
Author: importer
Created: 2011-11-29 04:23:52+00:00
State: open
Labels: Feature, framework

for convenience i organized the /templates folder at the root of TL for having subfolders relative to modules name:

/templates
/templates/frontend
/templates/newsletter
/templates/another_module_name..

here is how i modified the 2 functions in /system/libraries/Controller.php :

```
protected function getTemplate($strTemplate)
{
$strFile = sprintf('%s/templates/%s.tpl', TL_ROOT, $strTemplate);

if (

![](file_exists($strFile))
{
foreach ($this->Config->getActiveModules() as $strModule)
{
$strPath = sprintf('%s/templates/%s/%s.tpl', TL_ROOT, $strModule, $strTemplate);
if (file_exists($strPath)) {
$strFile = $strPath;
break;
}

$strPath = sprintf('%s/system/modules/%s/templates/%s.tpl', TL_ROOT, $strModule, $strTemplate);
if (file_exists($strPath)) {
$strFile = $strPath;
break;
}
}
}

if ()file_exists($strFile))
{
throw new Exception(sprintf('Could not find template file "%s"', $strTemplate));
}

return $strFile;
}
```

and

```
protected function getTemplateGroup($strPrefix)
{
$arrTemplates = array();
$arrFolders = array(TL_ROOT . '/templates');

foreach ($this->Config->getActiveModules() as $strModule)
{
$strFolder = sprintf('%s/templates/%s', TL_ROOT, $strModule);
if (is_dir($strFolder)) {
$arrFolders[] = $strFolder;
}

$strFolder = sprintf('%s/system/modules/%s/templates', TL_ROOT, $strModule);
if (is_dir($strFolder)) {
$arrFolders[] = $strFolder;
}
}

foreach ($arrFolders as $strFolder)
{
$arrFiles = preg_grep('/^' . preg_quote($strPrefix, '/') . '.*\.tpl$/i', scan($strFolder));

foreach ($arrFiles as $strTemplate)
{
$arrTemplates[] = basename($strTemplate, '.tpl');
}
}

return array_values(array_unique($arrTemplates));
}
```

that way it's still checking inside the root of /templates (i put there only fe_ templates) before checking /templates/module

it works for me and if you think it could be relevant enough, this could be a feature request

Related issues: #1348

--- _Originally created by anonymous on September 2nd, 2008, at 12:20pm (ID 46)_