-
-
Notifications
You must be signed in to change notification settings - Fork 339
/
Smarty.php
88 lines (80 loc) · 2.12 KB
/
Smarty.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?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\Smarty
* Adapter to use Smarty library as templating engine
*/
class Smarty extends Engine implements EngineInterface
{
/**
* @var \Smarty
*/
protected $smarty;
/**
* {@inheritdoc}
*
* @param ViewBaseInterface $view
* @param DiInterface $di
*/
public function __construct(ViewBaseInterface $view, DiInterface $di = null)
{
$this->smarty = new \Smarty();
$this->smarty->template_dir = '.';
$this->smarty->compile_dir = SMARTY_DIR . 'templates_c';
$this->smarty->config_dir = SMARTY_DIR . 'configs';
$this->smarty->cache_dir = SMARTY_DIR . 'cache';
$this->smarty->caching = false;
$this->smarty->debugging = true;
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();
}
foreach ($params as $key => $value) {
if (isset($params['_' . $key]) && $params['_' . $key] === true) {
$this->smarty->assign($key, $value, true);
} else {
$this->smarty->assign($key, $value);
}
}
$content = $this->smarty->fetch($path);
if ($mustClean) {
$this->_view->setContent($content);
} else {
echo $content;
}
}
/**
* Set Smarty's options
*
* @param array $options
*/
public function setOptions(array $options)
{
foreach ($options as $k => $v) {
$this->smarty->$k = $v;
}
}
/**
* Get Smarty object
*
* @return \Smarty
*/
public function getSmarty()
{
return $this->smarty;
}
}