Example #1
0
 function render_template($name)
 {
     $tmp_dir = Wordless::theme_temp_path();
     $template_path = Wordless::join_paths(Wordless::theme_views_path(), "{$name}.haml");
     if (!is_file($template_path)) {
         render_error("Template missing", "<strong>Ouch!!</strong> It seems that <code>{$template_path}</code> doesn't exist!");
     }
     if (!file_exists($tmp_dir)) {
         mkdir($tmp_dir, 0760);
     }
     if (!is_writable($tmp_dir)) {
         chmod($tmp_dir, 0760);
     }
     if (is_writable($tmp_dir)) {
         $haml = new HamlParser(array('style' => 'expanded', 'ugly' => false));
         include $haml->parse($template_path, $tmp_dir);
     } else {
         render_error("Temp dir not writable", "<strong>Ouch!!</strong> It seems that the <code>{$tmp_dir}</code> directory is not writable by the server! Go fix it!");
     }
 }
Example #2
0
 /**
  * Renders a template and its contained plartials. Accepts
  * a list of locals variables which will be available inside
  * the code of the template
  *
  * @param  string $name   The template filenames (those not starting
  *                        with an underscore by convention)
  *
  * @param  array  $locals An associative array. Keys will be variables'
  *                        names and values will be variable values inside
  *                        the template
  *
  * @see php.bet/extract
  *
  */
 function render_template($name, $locals = array())
 {
     $valid_filenames = array("{$name}.html.haml", "{$name}.haml", "{$name}.html.php", "{$name}.php");
     foreach ($valid_filenames as $filename) {
         $path = Wordless::join_paths(Wordless::theme_views_path(), $filename);
         if (is_file($path)) {
             $template_path = $path;
             $arr = explode('.', $path);
             $format = array_pop($arr);
             break;
         }
     }
     if (!isset($template_path)) {
         render_error("Template missing", "<strong>Ouch!!</strong> It seems that <code>{$name}.html.haml</code> or <code>{$name}.html.php</code> doesn't exist!");
     }
     extract($locals);
     switch ($format) {
         case 'haml':
             $tmp_dir = Wordless::theme_temp_path();
             if (!file_exists($tmp_dir)) {
                 mkdir($tmp_dir, 0760);
             }
             if (!is_writable($tmp_dir)) {
                 chmod($tmp_dir, 0760);
             }
             if (is_writable($tmp_dir)) {
                 $haml = new HamlParser(array('style' => 'expanded', 'ugly' => false));
                 include $haml->parse($template_path, $tmp_dir);
             } else {
                 render_error("Temp dir not writable", "<strong>Ouch!!</strong> It seems that the <code>{$tmp_dir}</code> directory is not writable by the server! Go fix it!");
             }
             break;
         case 'php':
             include $template_path;
             break;
     }
 }