emacs dumb-jump configuration
[phinde.git] / www / www-header.php
1 <?php
2 namespace phinde;
3 require_once __DIR__ . '/../src/init.php';
4
5 $GLOBALS['twig'] = new \Twig_Environment(
6     new \Twig_Loader_Filesystem(__DIR__ . '/../data/templates'),
7     array(
8         //'cache' => '/path/to/compilation_cache',
9         'debug' => true
10     )
11 );
12 $GLOBALS['twig']->addExtension(new \Twig_Extension_Debug());
13
14 $twig->addFunction('ellipsis', new \Twig_Function_Function('\phinde\ellipsis'));
15 function ellipsis($text, $maxlength)
16 {
17     if (strlen($text) > $maxlength) {
18         $text = substr($text, 0, $maxlength - 1) . '…';
19     }
20     return $text;
21 }
22
23 function render($tplname, $vars = array(), $return = false)
24 {
25     if (!isset($vars['htmlhelper'])) {
26         //$vars['htmlhelper'] = new HtmlHelper();
27     }
28     $vars['apptitle'] = $GLOBALS['phinde']['apptitle'];
29     $vars['baseUrl'] = '/';
30
31     $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
32     if ($return) {
33         return $template->render($vars);
34     } else {
35         echo $template->render($vars);
36     }
37 }
38 ?>