本文整理汇总了PHP中TemplateEngine类的典型用法代码示例。如果您正苦于以下问题:PHP TemplateEngine类的具体用法?PHP TemplateEngine怎么用?PHP TemplateEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemplateEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRenderWithAbsoluteTemplatePath
public function testRenderWithAbsoluteTemplatePath()
{
$engine = new TemplateEngine(__DIR__ . '/../fixtures/templates');
$result = $engine->render(__DIR__ . '/../fixtures/templates/1.php', array('message' => 'World'));
$this->assertNotEmpty($result);
//$this->assertEquals("<h1>Hello World</h1>\n", $result);
}
示例2: sendSystemEmailFromTemplate
/**
* Sends an e-mail (text format) from the system to the specified recipient.
* Difference to sendSystemEmail(): Content is extracted from a template file.
*
* @param WebSoccer $websoccer current context.
* @param I18n $i18n messages context
* @param string $recipient recipient e-mail address
* @param string $subject Already translated e-mail subject.
* @param string $templateName name of template (NOT template file name, i.e. WITHOUT file extension!) to use for the e-mail body.
* @param array $parameters array of parameters to use in the template (key=parameter name, value= parameter value).
*/
public static function sendSystemEmailFromTemplate(WebSoccer $websoccer, I18n $i18n, $recipient, $subject, $templateName, $parameters)
{
$emailTemplateEngine = new TemplateEngine($websoccer, $i18n, null);
$template = $emailTemplateEngine->loadTemplate('emails/' . $templateName);
$content = $template->render($parameters);
self::sendSystemEmail($websoccer, $recipient, $subject, $content);
}
示例3: actionView
public function actionView($id)
{
$articleModel = new ArticleModel();
$article = $articleModel->get($id);
if ($article === false) {
throw new Http404();
}
$templateEngine = new TemplateEngine();
return $templateEngine->render('articles/view.html', $article);
}
示例4: render
function render()
{
$template = new TemplateEngine($this->filepath);
$template->set($this->templateData);
$template->setGlobals($this->templateGlobals);
$template->display();
if (isset($_GET['DEBUG'])) {
echo '<pre>';
var_dump($this->templateData);
echo '</pre>';
}
}
示例5: getInstance
private static function getInstance()
{
if (self::$instance == null) {
self::$instance = new TemplateEngine();
}
return self::$instance;
}
示例6: beforeRender
public function beforeRender()
{
$menuSource = "";
foreach ($this->menuEntries as $name => $link) {
$menuSource .= '<li><a href="' . $link . '">' . $name . '</a></li>';
}
TemplateEngine::getInstance()->replaceMarks("menu", $menuSource);
}
示例7: renderTable
public function renderTable(TableContent $content)
{
$templates = array('widths' => $content->getTableWidths(), 'as_totals_box' => $content->getAsTotalsBox(), 'num_columns' => $content->getNumColumns(), 'data' => $content->getData(), 'headers' => $content->getHeaders(), 'auto_totals' => $content->getAutoTotals(), 'types' => $content->getDataTypes());
if ($templates['auto_totals']) {
$templates['totals'] = $content->getTotals();
}
$this->markup .= TemplateEngine::render(__DIR__ . '/html_templates/table.tpl', $templates);
}
示例8: __construct
private function __construct()
{
$this->classloader = Classloader::getInstance();
$this->classloader->initLoadLib();
$this->dataConnector = DataConnector::getInstance();
$this->routingEngine = RoutingEngine::getInstance();
$this->templateEngine = TemplateEngine::getInstance();
}
示例9: init
/**
* @see wcf\system\template\TemplateEngine::__construct()
*/
protected function init()
{
parent::init();
$this->templatePaths = array(1 => WCF_DIR . 'acp/templates/');
$this->compileDir = WCF_DIR . 'acp/templates/compiled/';
if (!defined('NO_IMPORTS')) {
$this->loadTemplateListeners();
}
}
示例10: renderTree
/**
* renders tree into menu template
* @return object
*/
public function renderTree()
{
if (!$this->getConfig()->template_menu) {
return;
}
if (!$this->tree) {
return;
}
$template = new TemplateEngine($this->templatePath . $this->getConfig()->template_menu);
$template->setCacheable(true);
$cache = Cache::getInstance();
if (!$cache->isCached('submenu')) {
$childs = array();
$childlist = $this->tree->getChildList($this->tree->getCurrentId());
foreach ($childlist as $item) {
if (isset($item['visible']) && !$item['visible']) {
continue;
}
$item['path'] = $this->tree->getPath($item['id']);
$childs[] = $item;
}
$template->setVariable('submenu', $childs, false);
$cache->save(serialize($childs), 'submenu');
} else {
$template->setVariable('submenu', unserialize($cache->getCache('submenu')), false);
}
// check if template is in cache
if ($template->isCached()) {
return $template;
}
$menu = $this->tree->getRootList();
// get selected main menu item
$firstNode = $this->tree->getFirstAncestorNode($this->tree->getCurrentId());
$firstId = $firstNode ? $firstNode['id'] : 0;
foreach ($menu as &$item) {
$item['path'] = isset($item['external']) && $item['external'] ? $item['url'] : $this->tree->getPath($item['id']);
$item['selected'] = $item['id'] == $firstId;
}
$template->setVariable('menu', $menu, false);
$auth = Authentication::getInstance();
$template->setVariable('loginName', $auth->getUserName(), false);
return $template;
}
示例11: render
/**
* Render informer html-code reserved for page URL
* Use cache
*
* @param $url
* @return string
*/
public function render($url)
{
$data = $this->getData($url);
if (!empty($data['informer_id'])) {
$engine = new TemplateEngine();
$cacheKey = 'compiled_' . $data['informer_id'];
$compiled = $this->cache->get($cacheKey);
if (!$compiled) {
$template = $this->getTemplate($data['informer_id']);
if (empty($template['error']) && !empty($template['code']) && !empty($template['items']) && isset($template['replace'])) {
$compiled = $engine->compileWithItems($template['code'], $template['items'], $template['replace']);
}
$this->cache->set($cacheKey, $compiled);
}
return $engine->render($compiled, $data['params']);
} else {
return '';
}
}
示例12: renderNavBar
function renderNavBar()
{
//Conexion a la BD
$db = DBManager::getInstance();
$db->connect();
$dbm = Driver::getInstance();
$navBar = new TemplateEngine();
//---x---x--- Por defecto ---x---x---
$navBar->log = 0;
//el usuario NO está logeado
$navBar->admin = 0;
//por lo tanto no puede ser administrador
$navBar->materia = 0;
//ni administrador de materia
$navBar->user_id = null;
//y no hay ID de usuario
//Se ha hecho login?
if (isset($_SESSION["name"])) {
//---x---x--- Si se ha hecho... ---x---x---
$navBar->log = 1;
//el usuario está logeado
$usuario = new Usuario($dbm);
$usuario = $usuario->findBy('user_name', $_SESSION['name']);
//CAMBIAME
$navBar->user_id = $usuario[0]->getUser_id();
//El usuario es un administrador?
if ($db->existUserRol($_SESSION["name"], "AdminApuntorium")) {
$navBar->admin = 1;
//el usuario es administrador
} else {
//El usuario es administrador de materia?
$administra = new Administra($dbm);
if ($administra->findBy('user_id', $usuario[0]->getUser_id()) != null) {
$navBar->materia = 1;
//el usuario administra una materia
}
}
} else {
}
return $navBar->render('navbar_v.php');
}
示例13: getInstance
/**
* Returns an instance of template engine driver.
* If the requested driver is already created, the same instance is returned.
*
* @param string $driver Name of the template engine driver. Must correspond to components.template_engine.engines.{$driver}.
*
* @return \Webiny\Component\TemplateEngine\Bridge\TemplateEngineInterface
* @throws TemplateEngineException
* @throws \Exception
*/
static function getInstance($driver)
{
if (isset(self::$instances[$driver])) {
return self::$instances[$driver];
}
$driverConfig = TemplateEngine::getConfig()->get('Engines.' . $driver, false);
if (!$driverConfig) {
throw new TemplateEngineException('Unable to read driver configuration: TemplateEngine.Engines.' . $driver);
}
try {
self::$instances[$driver] = TemplateEngineBridge::getInstance($driver, $driverConfig);
return self::$instances[$driver];
} catch (\Exception $e) {
throw $e;
}
}
示例14: init
protected function init($name) {
Logger::enter_group('Template');
Logger::debug('Loading Template');
$this->name = $name;
$this->tpl_engine = TemplateEngine::instance();
$this->tpl_engine->set_opts(array(
'loader' => array(
APP_ROOT . "/views/",
APP_ROOT . "/views/" . $this->name
),
'cache' => Config::instance('framework')->get_value('cache'),
'debug' => Config::instance('framework')->get_value('debug')
));
$this->tpl_engine->load();
}
示例15: redirectURI
if ($user != null && $user->checkPermissions(1, 1)) {
// falls Admin-Rechte
$isAdmin = 1;
} else {
$isAdmin = 0;
if ($user != null && $user->checkPermissions(0, 0, 0, 1, 1)) {
// wenn ORDERER
redirectURI("/orderer/index.php");
}
if ($user != null && $user->checkPermissions(0, 0, 1)) {
// wenn USER
redirectURI("/user/index.php");
}
}
$LOG = new Log();
$tpl = new TemplateEngine("template/viewProduct.html", "template/frame.html", $lang["viewer_viewProduct"]);
$LOG->write('3', 'viewer/viewProduct.php');
$pID = $_GET['pID'];
$tpl->assign('ID', $pID);
//Produktdaten
$product_query = DB_query("SELECT\n\t\t\t\t*\n\t\t\t\tFROM products\n\t\t\t\tWHERE products_id = " . $pID . "\n\t\t\t\tAND deleted = 0\n\t\t\t\tORDER BY sort_order, name\n\t\t\t\t");
$product = DB_fetchArray($product_query);
$tpl->assign('name', $product['name']);
$tpl->assign('description', $product['description']);
//$tpl->assign('sort_order',$product['sort_order']);
$tpl->assign('active', $product['active']);
// zur Unterscheidung, ob anzeigbar, weiterhin mitliefern
$tpl->assign('image_small', $product['image_small']);
$tpl->assign('image_big', $product['image_big']);
$tpl->assign('stock', $product['stock']);
$tpl->assign('price', $product['price']);