public function action_index() { // $this->response->body('Welcome'); $varhome = Smarty_View::factory('home.tpl'); $varhome->body2 = 'Variable content'; $varhome->body = Smarty_View::factory('formLogin.tpl'); $varhome->table = $this->load_table(); $this->response->body($varhome->render()); }
protected function _get_fields() { if ((bool) $this->_group) { //convert model fields to form fields foreach ($this->_fields[$this->_group] as $key => $field) { $this->_fields[$this->_group][$key] = Jelly_Form_Field::factory($field, $this->_view->smarty()); } $key = $this->_group; //clear current group $this->_group = null; return $this->_fields[$key]; } if (!isset($this->_fields['jelly_form_fields'])) { return; } //convert model fields to form fields foreach ($this->_fields['jelly_form_fields'] as $key => $field) { $this->_fields['jelly_form_fields'][$key] = Jelly_Form_Field::factory($field, $this->_view->smarty()); } return $this->_fields['jelly_form_fields']; }
public function action_index() { $var_myhome = Smarty_View::factory('myhome.tpl'); $this->response->body($var_myhome->render()); }
/** * Sets a global variable, similar to [View::set], except that the * variable will be accessible to all views. * * View::set_global($name, $value); * * @param string variable name or an array of variables * @param mixed value * @return void */ public static function set_global($key, $value = NULL) { if (is_array($key)) { foreach ($key as $key2 => $value) { View::$_global_data[$key2] = $value; if (self::$_smarty_is_loaded) { Smarty_View::smarty_prototype()->assignGlobal($key2, $value); } } } else { View::$_global_data[$key] = $value; if (self::$_smarty_is_loaded) { Smarty_View::smarty_prototype()->assignGlobal($key, $value); } } }
/** * Returns the current smarty object, creating it and the prototype if necessary * * @return Smarty object */ public function smarty() { // set time for benchmarking $time = microtime(TRUE); // see if we need to set up the smarty object for this instance if ($this->_smarty === NULL) { // see if we need to set up the prototype smarty object if (self::$_smarty_prototype === NULL) { // nearly everything can be done in the confif file $config = Kohana::$config->load('smarty'); // instantiate the prototype Smarty object require_once $config->smarty_class_file; $smarty = new Smarty(); self::$_smarty_prototype = $smarty; // set up the prototype with options from config file foreach ($config->smarty_config as $key => $value) { $smarty->{$key} = $value; } // deal with config options that are not simple properties $smarty->php_handling = constant($config->php_handling); if ($config->check_dirs) { // check we can write to the compiled templates directory if (!is_writeable($smarty->compile_dir)) { self::create_dir($smarty->compile_dir, 'Smarty compiled template'); } // if smarty caching is enabled, check we can write to the cache directory if ($smarty->caching && !is_writeable($smarty->cache_dir)) { self::create_dir($smarty->cache_dir, 'Smarty cache'); } } // now assign useful globals $smarty->assignGlobal('base_url', URL::base()); $smarty->assignGlobal('helper', new Smarty_Helper()); // and register useful plugins // set timing for benchmark self::$_init_time = microtime(TRUE) - $time; } $this->_smarty = clone self::$_smarty_prototype; $time = microtime(TRUE) - $time; $this->_clone_time = $time; self::$_total_clone_time += $time; self::$_clone_count++; } return $this->_smarty; }
/** * Returns the smarty prototype object, creating it if necessary * * @return Smarty prototype object */ public static function smarty_prototype() { // set time for benchmarking $time = microtime(TRUE); // see if we need to set up the prototype smarty object if (self::$_smarty_prototype === NULL) { // nearly everything can be done in the config file if (Kohana::VERSION > '3.2') { $config = Kohana::$config->load('smarty'); } else { $config = Kohana::config('smarty'); } // locate a Smarty class - first check if it is already loaded if (!class_exists('Smarty', false)) { // next check if a path is set in config/smarty.php if ($file = $config->smarty_class_file) { require_once $file; // save the location in case we have more than one Smarty version around self::$_smarty_path = realpath(dirname($file)) . DIRECTORY_SEPARATOR; } elseif (!class_exists('Smarty')) { // try and autoload it // if it doesn't autoload, fall back to letting Kohana find the bundled version $file = Kohana::find_file('vendor', 'smarty/libs/Smarty.class'); require_once $file; // save the location in case we have more than one Smarty version around self::$_smarty_path = realpath(dirname($file)) . DIRECTORY_SEPARATOR; } } // instantiate the prototype Smarty object $smarty = new Smarty(); self::$_smarty_prototype = $smarty; // set up the prototype with options from config file foreach ($config->smarty_config as $key => $value) { $smarty->{$key} = $value; } // deal with config options that are not simple properties $smarty->php_handling = constant($config->php_handling); // add the path to the plugins for the located Smarty distro $smarty->addPluginsDir(self::$_smarty_path . 'plugins'); // add views directories for all loaded modules (including Smarty3) $dirs = array(); foreach (Kohana::modules() as $dir) { $dirs[] = "{$dir}views"; } $smarty->addTemplateDir($dirs); if ($config->check_dirs) { // check we can write to the compiled templates directory if (!is_writeable($smarty->compile_dir)) { self::create_dir($smarty->compile_dir, 'Smarty compiled template'); } // if smarty caching is enabled, check we can write to the cache directory if ($smarty->caching && !is_writeable($smarty->cache_dir)) { self::create_dir($smarty->cache_dir, 'Smarty cache'); } } // now assign useful globals $smarty->assignGlobal('base_url', URL::base()); $smarty->assignGlobal('helper', new Smarty_Helper()); $bound = View::$_global_bound_variables; // register any globals foreach (View::$_global_data as $key => $value) { if (isset($bound[$key])) { Smarty::$global_tpl_vars[$key] = new Smarty_variable($value); Smarty::$global_tpl_vars[$key]->value =& $value; } else { $smarty->assignGlobal($key, $value); } } // and register useful plugins // add to registered template engines View::$_smarty_is_loaded = TRUE; // set timing for benchmark self::$_init_time = microtime(TRUE) - $time; } return self::$_smarty_prototype; }