Example #1
0
 /**
  * render
  * Finds and chooses the correct template, then renders the page
  *
  * @param string $template Template (or array of templates, in order of preference) to render the page with
  * @return string
  */
 public function render($template)
 {
     $html = '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">No template found.</p>';
     $list = $template ? $list = array($template) : self::$_templates;
     $template_type = 'html';
     // Allow setting where to get the template from
     if (!self::$_template_location) {
         self::$_template_location = Path::assemble(BASE_PATH, Config::getTemplatesPath(), 'templates');
     }
     foreach ($list as $template) {
         $template_path = Path::assemble(self::$_template_location, $template);
         $override_path = Path::assemble(BASE_PATH, Config::getThemesPath(), Config::getTheme(), 'admin', $template);
         if (File::exists($template_path . '.html') || file_exists($template_path . '.php')) {
             // set debug information
             Debug::setValue('template', $template);
             Debug::setvalue('layout', str_replace('layouts/', '', self::$_layout));
             Debug::setValue('statamic_version', STATAMIC_VERSION);
             Debug::setValue('php_version', phpversion());
             Debug::setValue('theme', array_get($this->data, '_theme', null));
             Debug::setValue('environment', array_get($this->data, 'environment', '(none)'));
             $this->data['_debug'] = array('template' => Debug::getValue('template'), 'layout' => Debug::getValue('layout'), 'version' => Debug::getValue('statamic_version'), 'statamic_version' => Debug::getValue('statamic_version'), 'php_version' => Debug::getValue('php_version'), 'theme' => Debug::getValue('theme'), 'environment' => Debug::getValue('environment'));
             # standard lex-parsed template
             if (File::exists($template_path . '.html')) {
                 $template_type = 'html';
                 $this->appendNewData($this->data);
                 // Fetch template and parse any front matter
                 $template = Parse::frontMatter(File::get($template_path . '.html'));
                 self::$_extra_data = $template['data'] + self::$_extra_data;
                 $this->prependNewData(self::$_extra_data);
                 $html = Parse::template($template['content'], Statamic_View::$_dataStore, array($this, 'callback'));
                 break;
                 # lets forge into raw data
             } elseif (File::exists($override_path . '.php') || File::exists($template_path . '.php')) {
                 $template_type = 'php';
                 extract($this->data);
                 ob_start();
                 if (File::exists($override_path . '.php')) {
                     $template_path = $override_path;
                 }
                 require $template_path . ".php";
                 $html = ob_get_clean();
                 break;
             } else {
                 Log::error("Template does not exist: '{$template_path}'", 'core');
             }
         }
     }
     // mark milestone for debug panel
     Debug::markMilestone('template rendered');
     // get rendered HTML
     $rendered = $this->_render_layout($html, $template_type);
     // mark milestone for debug panel
     Debug::markMilestone('layout rendered');
     // store it into the HTML cache if needed
     if (Addon::getAPI('html_caching')->isEnabled()) {
         Addon::getAPI('html_caching')->putCachedPage($rendered);
     }
     // return rendered HTML
     return $rendered;
 }
Example #2
0
 /**
  * Returns a list of templates for this theme
  *
  * @param string  $theme  Optional theme to list from, otherwise, current theme
  * @return array
  */
 public static function getTemplates($theme = NULL)
 {
     $templates = array();
     $finder = new Finder();
     $files = $finder->files()->in(Path::assemble(BASE_PATH, Config::getThemesPath(), Config::getTheme(), 'templates'))->name('*.html')->followLinks();
     if (iterator_count($files) > 0) {
         foreach ($files as $file) {
             $templates[] = str_replace('.' . $file->getExtension(), '', $file->getRelativePathname());
         }
     }
     return $templates;
 }
 public function getThemeSettingsPath()
 {
     return Path::assemble(BASE_PATH, Config::getThemesPath(), Config::getTheme(), '/theme.yaml');
 }