]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/template/class_BaseTemplateEngine.php
Image engine rewritten, cache directories ignored
[core.git] / inc / classes / main / template / class_BaseTemplateEngine.php
index 9abcd4b9fdbdef7a4bac3285c1d1c51742d64b73..190e2e8054085ea72373fc576327dac03cdaf081 100644 (file)
@@ -306,7 +306,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $templateType   The current template's type
         * @return      void
         */
-       private final function setTemplateType ($templateType) {
+       protected final function setTemplateType ($templateType) {
                $this->templateType = (string) $templateType;
        }
 
@@ -350,6 +350,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                return $this->templateBasePath;
        }
 
+       /**
+        * Getter for generic base path
+        *
+        * @return      $templateBasePath               The relative base path for all templates
+        */
+       public final function getGenericBasePath () {
+               // And set it
+               return $this->genericBasePath;
+       }
+
        /**
         * Setter for template extension
         *
@@ -516,30 +526,44 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         *
         * @param       $template       The template we shall load
         * @return      void
+        * @throws      FileNotFoundException   If the template was not found
         */
-       private function loadTemplate ($template) {
-               // Get extension for the template
-               $ext = $this->getRawTemplateExtension();
-
-               // If we shall load a code-template we need to switch the file extension
-               if ($this->getTemplateType() == $this->getConfigInstance()->readConfig('code_template_type')) {
-                       // Switch over to the code-template extension
-                       $ext = $this->getCodeTemplateExtension();
+       protected function loadTemplate ($template, $ext = '') {
+               // Get extension for the template if empty
+               if (empty($ext)) {
+                       // None provided, so get the raw one
+                       $ext = $this->getRawTemplateExtension();
                } // END - if
 
                // Construct the FQFN for the template by honoring the current language
                $fqfn = sprintf("%s%s%s%s/%s/%s%s",
                        $this->getConfigInstance()->readConfig('base_path'),
                        $this->getTemplateBasePath(),
-                       $this->genericBasePath,
+                       $this->getGenericBasePath(),
                        $this->getLanguageInstance()->getLanguageCode(),
                        $this->getTemplateType(),
                        (string) $template,
                        $ext
                );
 
-               // Load the raw template data
-               $this->loadRawTemplateData($fqfn);
+               // First try this
+               try {
+                       // Load the raw template data
+                       $this->loadRawTemplateData($fqfn);
+               } catch (FileNotFoundException $e) {
+                       // If we shall load a code-template we need to switch the file extension
+                       if ($this->getTemplateType() != $this->getConfigInstance()->readConfig('web_template_type')) {
+                               // Switch over to the code-template extension and try it again
+                               $ext = $this->getCodeTemplateExtension();
+
+                               // Try it again...
+                               $this->loadTemplate($template, $ext);
+                       } else {
+                               // Throw it again
+                               throw new FileNotFoundException($fqfn, FrameworkFileInputPointer::EXCEPTION_FILE_NOT_FOUND);
+                       }
+               }
+
        }
 
        /**