From: Andrey Kutejko Date: Sun, 7 Jul 2013 06:44:33 +0000 (+0300) Subject: app level templates X-Git-Tag: 0.5~184 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=9c7f589bab40ed20699cb07a6b34d9153fa6855a;p=ipf.git app level templates --- diff --git a/doc/template.org b/doc/template.org index 4ce9d28..3a599c9 100644 --- a/doc/template.org +++ b/doc/template.org @@ -2,6 +2,8 @@ This document describes template language of IPF framework. + Templates are placed in 'templates' directories of project or application. + =[ ]?= -- optional code =[ ]*= -- code can be repeated zero or more times. @@ -127,6 +129,5 @@ + =template_tags= -- additional template tags + =template_modifiers= -- additional template modifiers + =template_context_processors= -- list of context processors - + =template_dirs= -- list of directories to look for template files. By default it contains 'templates' folder in project directory and 'templates' folder in IPF_Admin application (when it is enabled). + =debug= -- forces to recompile template before each rendering diff --git a/ipf.php b/ipf.php index 6123db7..79789a3 100644 --- a/ipf.php +++ b/ipf.php @@ -53,13 +53,6 @@ final class IPF if (!is_array(IPF::$settings['applications'])) throw new IPF_Exception_Settings('applications must be array of string'); - if (!isset(IPF::$settings['template_dirs'])){ - IPF::$settings['template_dirs'] = array(); - IPF::$settings['template_dirs'][] = IPF::$settings['project_path'].DIRECTORY_SEPARATOR.'templates'; - if (array_search('IPF_Admin',IPF::$settings['applications'])) - IPF::$settings['template_dirs'][] = IPF::$settings['ipf_path'].DIRECTORY_SEPARATOR.'ipf'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates'; - } - if (!isset(IPF::$settings['admin_title'])){ IPF::$settings['admin_title'] = 'IPF Administration'; } diff --git a/ipf/template/environment.php b/ipf/template/environment.php index 7d3d79a..0ea8b8e 100644 --- a/ipf/template/environment.php +++ b/ipf/template/environment.php @@ -10,8 +10,21 @@ abstract class IPF_Template_Environment public static function getDefault() { - if (!self::$defaultEnvironment) - self::$defaultEnvironment = new IPF_Template_Environment_FileSystem(IPF::get('template_dirs'), IPF::get('tmp')); + if (!self::$defaultEnvironment) { + $dirs = array(); + + $projectTemplates = IPF::get('project_path') . '/templates'; + if (is_dir($projectTemplates)) + $dirs[] = $projectTemplates; + + foreach (IPF_Project::getInstance()->appList() as $app) { + $applicationTemplates = $app->getPath() . 'templates'; + if (is_dir($applicationTemplates)) + $dirs[] = $applicationTemplates; + } + + self::$defaultEnvironment = new IPF_Template_Environment_FileSystem($dirs, IPF::get('tmp')); + } return self::$defaultEnvironment; } }