4 * Class CRM_Core_CodeGen_Util_Smarty
6 class CRM_Core_CodeGen_Util_Smarty
{
8 * @var CRM_Core_CodeGen_Util_Smarty
10 private static $singleton;
13 * @return CRM_Core_CodeGen_Util_Smarty
15 public static function singleton() {
16 if (self
::$singleton === NULL) {
17 self
::$singleton = new CRM_Core_CodeGen_Util_Smarty();
19 return self
::$singleton;
24 public function __destruct() {
25 if ($this->compileDir
) {
26 CRM_Core_CodeGen_Util_File
::cleanTempDir($this->compileDir
);
31 * Get templates_c directory.
35 public function getCompileDir() {
36 if ($this->compileDir
=== NULL) {
37 $this->compileDir
= CRM_Core_CodeGen_Util_File
::createTempDir('templates_c_');
39 return $this->compileDir
;
43 * Create a Smarty instance.
47 public function createSmarty() {
48 $base = dirname(dirname(dirname(dirname(__DIR__
))));
50 require_once 'Smarty/Smarty.class.php';
51 $smarty = new Smarty();
52 $smarty->template_dir
= "$base/xml/templates";
53 $smarty->plugins_dir
= ["$base/packages/Smarty/plugins", "$base/CRM/Core/Smarty/plugins"];
54 $smarty->compile_dir
= $this->getCompileDir();
55 $smarty->clear_all_cache();
57 // CRM-5308 / CRM-3507 - we need {localize} to work in the templates
59 require_once 'CRM/Core/Smarty/plugins/block.localize.php';
60 $smarty->register_block('localize', 'smarty_block_localize');