Merge pull request #17187 from alexymik/recur_contribution_source
[civicrm-core.git] / setup / src / Setup / SmartyUtil.php
1 <?php
2 namespace Civi\Setup;
3
4 class SmartyUtil {
5
6 /**
7 * Create a Smarty instance.
8 *
9 * @return \Smarty
10 */
11 public static function createSmarty($srcPath) {
12 require_once 'CRM/Core/I18n.php';
13
14 $packagePath = PackageUtil::getPath($srcPath);
15 require_once $packagePath . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'Smarty.class.php';
16
17 $smarty = new \Smarty();
18 $smarty->template_dir = implode(DIRECTORY_SEPARATOR, [$srcPath, 'xml', 'templates']);
19 $smarty->plugins_dir = [
20 implode(DIRECTORY_SEPARATOR, [$packagePath, 'Smarty', 'plugins']),
21 implode(DIRECTORY_SEPARATOR, [$srcPath, 'CRM', 'Core', 'Smarty', 'plugins']),
22 ];
23 $smarty->compile_dir = \Civi\Setup\FileUtil::createTempDir('templates_c');
24 $smarty->clear_all_cache();
25
26 // CRM-5308 / CRM-3507 - we need {localize} to work in the templates
27 require_once implode(DIRECTORY_SEPARATOR, [$srcPath, 'CRM', 'Core', 'Smarty', 'plugins', 'block.localize.php']);
28 $smarty->register_block('localize', 'smarty_block_localize');
29 $smarty->assign('gencodeXmlDir', "$srcPath/xml");
30
31 return $smarty;
32 }
33
34 }