forked from phalcon/incubator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMustache.php
53 lines (47 loc) · 1.21 KB
/
Mustache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Phalcon\Mvc\View\Engine;
use Phalcon\DiInterface;
use Phalcon\Mvc\View\Engine;
use Phalcon\Mvc\View\EngineInterface;
use Phalcon\Mvc\ViewBaseInterface;
/**
* Phalcon\Mvc\View\Engine\Mustache
* Adapter to use Mustache library as templating engine
*/
class Mustache extends Engine implements EngineInterface
{
/**
* @var \Mustache_Engine
*/
protected $mustache;
/**
* {@inheritdoc}
*
* @param ViewBaseInterface $view
* @param DiInterface $di
*/
public function __construct(ViewBaseInterface $view, DiInterface $di = null)
{
$this->mustache = new \Mustache_Engine();
parent::__construct($view, $di);
}
/**
* {@inheritdoc}
*
* @param string $path
* @param array $params
* @param boolean $mustClean
*/
public function render($path, $params, $mustClean = false)
{
if (!isset($params['content'])) {
$params['content'] = $this->_view->getContent();
}
$content = $this->mustache->render(file_get_contents($path), $params);
if ($mustClean) {
$this->_view->setContent($content);
} else {
echo $content;
}
}
}