public function Run() { $the_tpl = $this->ControllerGetParam('module-path') . 'views/sample.twig.htm'; // render using only this module $this->PageViewSetVars(['title' => 'Sample Twig Templating', 'main' => (new \SmartModExtLib\TplTwig\Templating())->render((string) $the_tpl, ['hello' => '<h1>Hello World (Rendered using Module TplTwig for Smart.Framework)</h1>', 'navigation' => array(array('href' => '#link1', 'caption' => 'Link1'), array('href' => '#link2', 'caption' => 'Link2'))])]); // alternate (better) rendering, using the smart-extra-libs if (class_exists('SmartTwigTemplating')) { $this->PageViewAppendVar('main', '<hr size="1">' . SmartTwigTemplating::render_file_template((string) $the_tpl, ['hello' => '<h1>Hello, Again (Render using Smart.Framework.Modules/Smart-Extra-Libs)</h1>', 'navigation' => array(array('href' => '#link3', 'caption' => 'Link3'), array('href' => '#link4', 'caption' => 'Link4'))])); } //end if }
public static function render_file_template($file, $arr_vars = array()) { //-- if (!SmartAppInfo::TestIfModuleExists('mod-tpl-twig')) { return '{# ERROR: SmartTwigTemplating :: The module mod-tpl-twig cannot be found ... #}'; } //end if //-- if (self::$twig === null) { self::$twig = new \SmartModExtLib\TplTwig\Templating(); } //end if //-- return (string) self::$twig->render((string) $file, (array) $arr_vars); //-- }