public function render($view) { if ($this->tpl->template_exists($view)) { return $this->tpl->fetch($view); } else { throw new ViewNotFoundException($view); } }
/** * Плагин для смарти * Подключает обработчик блоков шаблона * * @param array $aParams * @param Smarty $oSmarty * @return string */ function smarty_insert_block($aParams, &$oSmarty) { /** * Устанавливаем шаблон */ $sBlock = ucfirst(basename($aParams['block'])); /** * Проверяем наличие шаблона. Определяем значения параметров работы в зависимости от того, * принадлежит ли блок одному из плагинов, или является пользовательским классом движка */ if (isset($aParams['params']) and isset($aParams['params']['plugin'])) { require_once Config::Get('path.root.server') . '/engine/classes/ActionPlugin.class.php'; $sBlockTemplate = Plugin::GetTemplatePath($aParams['params']['plugin']) . '/block.' . $aParams['block'] . '.tpl'; $sBlockClass = Config::Get('path.root.server') . '/plugins/' . $aParams['params']['plugin'] . '/classes/blocks/Block' . $sBlock . '.class.php'; $sCmd = '$oBlock=new Plugin' . ucfirst($aParams['params']['plugin']) . '_Block' . $sBlock . '($aParamsBlock);'; } else { $sBlockTemplate = Engine::getInstance()->Plugin_GetDelegate('template', 'block.' . $aParams['block'] . '.tpl'); $sBlockClass = Config::Get('path.root.server') . '/classes/blocks/Block' . $sBlock . '.class.php'; $sCmd = '$oBlock=new Block' . $sBlock . '($aParamsBlock);'; } if (!isset($aParams['block']) or !$oSmarty->template_exists($sBlockTemplate)) { $oSmarty->trigger_error("Not found template for block: " . $sBlockTemplate); return; } /** * параметры */ $aParamsBlock = array(); if (isset($aParams['params'])) { $aParamsBlock = $aParams['params']; } /** * Подключаем необходимый обработчик */ require_once $sBlockClass; eval($sCmd); /** * Запускаем обработчик */ $oBlock->Exec(); /** * Возвращаем результат в виде обработанного шаблона блока */ return $oSmarty->fetch($sBlockTemplate); }
/** * Проверяет существование шаблона * * @param string $sTemplate * @return bool */ public function TemplateExists($sTemplate) { return $this->oSmarty->template_exists($sTemplate); }
} $email_message->SetEncodedHeader("Subject", $subject); /* * If you are not going to personalize the message body for each recipient, * set the cache_body flag to 1 to reduce the time that the class will take * to regenerate the message to send to each recipient */ $email_message->cache_body = 0; /* * Lets use two distinct Smarty objects for composing the HTML and text * parts and avoid the need to re-assign constant values when switching * contexts. */ $html_smarty = new Smarty(); $text_smarty = new Smarty(); if (!$html_smarty->template_exists($template = "mailing.html.tpl") || !$text_smarty->template_exists($template = "mailing.txt.tpl")) { echo "Please copy the template file templates/" . $template . " to your Smarty templates directory.\n"; exit; } /* Create empty parts for the parts that will be personalized for each recipient. * HTML message values should be escaped with HTMLEntities(). */ $html_smarty->assign("subject", HtmlEntities($subject)); $html_smarty->assign("fromname", HtmlEntities($from_name)); $html_smarty->assign("firstname", ""); $html_smarty->assign("balance", "0"); $html_smarty->assign("email", "?"); $html_message = $html_smarty->fetch("mailing.html.tpl"); $email_message->CreateQuotedPrintableHTMLPart($html_message, "", $html_part); /* * It is strongly recommended that when you send HTML messages,
/* * The form is ready to be processed, just output it again as read only to * display the submitted values. A real form processing script usually may * do something else like storing the form values in a database. */ $form->ReadOnly = 1; } /* * Create the Smarty engine object to process the form template first * * NOTE: the form template needs to be processed separately from any other * page templates to prevent that the form prefilter interferes with the * normal processing of the other templates */ $smarty = new Smarty(); if ($smarty->template_exists("form.tpl")) { $smarty->assign_by_ref("form", $form); $smarty->assign("title", "Form class test"); $smarty->assign("error_message", $error_message); $smarty->assign_by_ref("verify", $verify); $smarty->assign("doit", $doit); $smarty->assign("mark", "[Verify]"); $smarty->assign("credit_card_field", "credit_card_number"); $smarty->register_prefilter("smarty_prefilter_form"); $smarty->fetch("form.tpl"); $smarty->unregister_prefilter("smarty_prefilter_form"); } else { $form->AddDataPart("<h2><center>Please copy the template file <tt>templates/form.tpl</tt> to your Smarty <tt>templates</tt> directory.</center></h2>\n"); $doit = 1; } /*
public function template_exists($resource_name) { if (method_exists($this, "templateExists")) { return $this->templateExists($resource_name); } else { return parent::template_exists($resource_name); } }