/** * Constructor. * * @see sfView */ public function initialize($context, $moduleName, $actionName, $viewName) { $ret = parent::initialize($context, $moduleName, $actionName, $viewName); $this->viewCache = $this->context->getViewCacheManager(); if (sfConfig::get('sf_cache')) { $this->checkCache = sfConfig::get('sf_lazy_cache_key') ? $this->viewCache->isActionCacheable($moduleName, $actionName) : true; } return $ret; }
/** * sfSmartyView::initialize() * This method is used instead of sfPHPView::initialze * * @param mixed $context * @param mixed $moduleName * @param mixed $actionName * @param mixed $viewName * @return **/ public function initialize($context, $moduleName, $actionName, $viewName) { $this->setExtension(sfConfig::get('app_sfSmarty_template_extension', '.tpl')); parent::initialize($context, $moduleName, $actionName, $viewName); self::$smarty = sfSmarty::getInstance(); if (sfConfig::get('sf_logging_enabled')) { $this->dispatcher->notify(new sfEvent($this, 'application.log', array('{sfSmartyView} is used for rendering'))); } return true; }
<?php /** * Smarty TagHelpers class for symfony, * helpers to use the tag helpers in a more smartyish way * * @version $Id$ * @copyright 2006 Georg Gell */ class SmartyTagHelper { public static function cdata(array $params, $content, Smarty $smarty, &$repeat) { if (!$repeat) { return "//<![CDATA[\n{$content}\n//]]>"; } } } sfSmartyView::registerBlock('cdata', array('SmartyTagHelper', 'cdata'));
/** * Smarty EscapingHelpers class for symfony, * helpers to use the escaping helpers in a more smartyish way * * @version $Id$ * @copyright 2006 Georg Gell */ class SmartyEscapingHelper { public static function esc_entities($content) { return esc_entities($content); } public static function esc_js($content) { return esc_js($content); } public static function esc_js_no_entities($content) { return esc_js_no_entities($content); } public static function esc_raw($content) { return esc_raw($content); } } sfSmartyView::registerModifier('esc_entities', array('SmartyEscapingHelper', 'esc_entities')); sfSmartyView::registerModifier('esc_js', array('SmartyEscapingHelper', 'esc_js')); sfSmartyView::registerModifier('esc_js_no_entities', array('SmartyEscapingHelper', 'esc_js_no_entities')); sfSmartyView::registerModifier('esc_raw', array('SmartyEscapingHelper', 'esc_raw'));
<?php /** * Smarty JavascriptHelpers class for symfony, * helpers to use the javascript helpers in a more smartyish way * * @version $Id$ * @copyright 2006 Georg Gell */ class SmartyJavascriptHelper { public static function javascript(array $params, $content, Smarty $smarty, &$repeat) { if (!$repeat) { return javascript_tag($content); } } } sfSmartyView::registerBlock('javascript', array('SmartyJavascriptHelper', 'javascript'));
/** * sfSmarty::renderFile() * render template file using Smarty * * @param sfSmartyView $view * @param mixed $file * @return * @access protected **/ public function renderFile($view, $file) { $sf_context = sfContext::getInstance(); $sf_request = $sf_context->getRequest(); $sf_params = $sf_request->getParameterHolder(); $sf_user = $sf_context->getUser(); if ($view->getAttribute('sf_type') == 'layout') { self::$smarty->compile_id = $view->getDecoratorTemplate(); } else { self::$smarty->compile_id = $view->getModuleName(); } $this->loadCoreAndStandardHelpers(); $_escaping = $view->getAttributeHolder()->getEscaping(); if ($_escaping === true || $_escaping == 'on') { $sf_data = $this->getSfData($view, $view->getAttributeHolder()->getEscapingMethod()); } elseif ($_escaping === false || $_escaping == 'off') { $sf_data = $this->getSfData($view); $data =& $view->getAttributeHolder()->getAll(); foreach ($data as $key => &$value) { self::$smarty->assign_by_ref($key, $value); } } // we need to add the data to smarty self::$smarty->assign_by_ref('sf_data', $sf_data); // we need to add the context to smarty self::$smarty->assign_by_ref('sf_context', $sf_context); // we need to add the request to smarty self::$smarty->assign_by_ref('sf_request', $sf_request); // we need to add the params to smarty self::$smarty->assign_by_ref('sf_params', $sf_params); // we need to add the user to smarty self::$smarty->assign_by_ref('sf_user', $sf_user); return self::$smarty->fetch("file:{$file}"); }