本文整理汇总了PHP中PHPTAL::setSource方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPTAL::setSource方法的具体用法?PHP PHPTAL::setSource怎么用?PHP PHPTAL::setSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPTAL
的用法示例。
在下文中一共展示了PHPTAL::setSource方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
public function generate()
{
// getting view file contents, and stripping from <?php die?\>
$viewContent = file_get_contents($this->_viewPath);
$viewContent = str_replace('<?php die?>', '', $viewContent);
$viewContent = '<tal:block>' . $viewContent . '</tal:block>';
// PHPTAL configuration
$view = new PHPTAL();
$view->setSource($viewContent, $this->_viewPath);
foreach ($this->_params as $key => $value) {
$view->set($key, $value);
}
$view->setOutputMode(PHPTAL::HTML5);
// PHPTAL filters
$view->addPreFilter(new ViewPreFilter());
// <? --> <?php, <?= --> <?php echo
$view->addPreFilter(new PHPTAL_PreFilter_StripComments());
if (!defined('WM_Debug')) {
$view->addPreFilter(new PHPTAL_PreFilter_Normalize());
// strips whitespaces etc.
}
// predefined parameters
// (NOTE: when changed, change also array in ->__set())
if (class_exists('Users')) {
$view->set('isAdmin', Users::isLogged());
}
// executing
return $view->execute();
}
示例2: PHPTALWithSource
private function PHPTALWithSource($source)
{
global $PhptalCacheTest_random;
$tpl = new PHPTAL();
$tpl->setForceReparse(false);
$tpl->setSource($source . "<!-- {$this->PhptalCacheTest_random} -->");
// avoid cached templates from previous test runs
return $tpl;
}
示例3: render
public function render(&$toolbar)
{
if (!class_exists('PHPTAL')) {
require 'PHPTAL.php';
}
$tal = new PHPTAL();
$tal->toolbar = $toolbar;
$tal->setSource($this->template);
$html = $tal->execute();
return $html;
}
示例4: execute
public function execute($view)
{
parent::execute($view);
return $view->render();
$context = Joy_Context::getInstance();
$resource = $view->getResourceList();
$context->response->addScript($resource["javascripts"]);
$context->response->addStyle($resource["stylesheets"]);
$application = $context->config->application->get("application");
$application["i18n"] = $view->getLocale();
$tpl = new PHPTAL();
$tpl->setSource($view->getTemplate());
$tpl->import = new Joy_Render_Template_Importer($view);
$tpl->application = $application;
$tpl->get = (array) $view->assignAll();
return $tpl->execute();
}
示例5: vanilla_shortcode
function vanilla_shortcode($shortcode)
{
global $tpl_set, $tpl;
$active_template = vanilla_get_template('shortcodes/' . $shortcode . ".html");
if (!$active_template) {
return "";
}
// No need to include the PHP tpl file here. Already loaded at init.
$tpl_source = '<metal:block define-macro="' . $shortcode . '_shortcode">' . "\n" . "<!-- shortcode: " . $shortcode . " -->\n" . '<span tal:condition="php:VANILLA_DEBUG" class="widget-debug">SHORTCODE: ' . $shortcode . '</span>' . "\n" . '<span metal:use-macro="' . $active_template . '/loader" />' . "\n" . '<span metal:define-slot="' . $shortcode . '" />' . "\n" . '</metal:block><metal:block use-macro="' . $shortcode . '_shortcode" />' . "\n";
//return "<textarea style='width:500px; height:300px;'> $tpl_source </textarea>";
// Load and fire the PHPTAL template!
$template = new PHPTAL();
$template->setSource($tpl_source, $tpl_set . $shortcode);
$template->set('vanilla', $tpl);
try {
return $template->execute();
} catch (Exception $e) {
return $e;
}
}
示例6: display
/**
* Show the loaded contents using the template engine
*
* @param string $content Content to display
*/
public function display()
{
$data = $_MIDCOM->context->get();
$cache_file = $this->cache_directory . '/' . $this->get_cache_identifier() . '.php';
ob_start();
include $cache_file;
$content = ob_get_clean();
// FIXME: Remove this once we can actually invalidate cache
unlink($cache_file);
switch ($data['template_engine']) {
case 'tal':
if (!class_exists('PHPTAL')) {
require 'PHPTAL.php';
include_once 'TAL/modifiers.php';
}
if ($_MIDCOM->timer) {
$_MIDCOM->timer->setMarker('post-require');
}
$tal = new PHPTAL($this->get_cache_identifier());
$tal->show_toolbar = false;
if (isset($_MIDCOM->toolbar) && $_MIDCOM->toolbar->can_view()) {
$tal->show_toolbar = true;
}
if ($_MIDCOM->timer) {
$_MIDCOM->timer->setMarker('post-set-show_toolbar');
}
$tal->uimessages = false;
$uimessages = $_MIDCOM->serviceloader->load('uimessages');
if ($uimessages->has_messages() && $uimessages->can_view()) {
$tal->uimessages = $uimessages->render();
}
if ($_MIDCOM->timer) {
$_MIDCOM->timer->setMarker('post-set-show_uimessages');
}
//TODO: Do something else here :)
$tal->navigation = false;
/*$tal->navigation = $_MIDCOM->navigation;
if ($_MIDCOM->timer)
{
$_MIDCOM->timer->setMarker('post-set-navigation');
}*/
$tal->MIDCOM = $_MIDCOM;
if ($_MIDCOM->timer) {
$_MIDCOM->timer->setMarker('post-set-MIDCOM');
}
foreach ($data as $key => $value) {
$tal->{$key} = $value;
if ($_MIDCOM->timer) {
$_MIDCOM->timer->setMarker("post-set-{$key}");
}
}
$tal->setSource($content);
if ($_MIDCOM->timer) {
$_MIDCOM->timer->setMarker('post-source');
}
$content = $tal->execute();
if ($_MIDCOM->timer) {
$_MIDCOM->timer->setMarker('post-execute');
}
break;
default:
break;
}
echo $content;
if ($_MIDCOM->timer && $_MIDCOM->context->get_current_context() == 0 && $_MIDCOM->context->mimetype == 'text/html') {
$_MIDCOM->timer->display();
}
if ($_MIDCOM->configuration->get('enable_included_list')) {
$included = get_included_files();
echo "<p>" . count($included) . " included files:</p>\n";
echo "<ul>\n";
foreach ($included as $filename) {
echo "<li>{$filename}</li>\n";
}
echo "</ul>\n";
}
///TODO: Connect this to some signal that tells the MidCOM execution has ended.
$uimessages = $_MIDCOM->serviceloader->load('uimessages');
$uimessages->store();
}
示例7: foreach
/*foreach ($q as $row) {
//$r .= '<li>' . $row['obj'] . ' - ' . $row['rel'] . ' - ' . $row['subj'] . '</li>';
if ($rows = $row->getTempl()){
foreach ($rows as $name) {
$r .= '<li>' . $name . '</li>';
}
}
if ($rows = $row->getObj('?rel')){
foreach ($rows as $name) {
$r .= '<li>' . $name . '</li>';
}
}
}*/
// создать обработчик шаблонов
$template = new PHPTAL();
$template->setSource($store->getTempl('foaf:Person'));
$editortmpl = new PHPTAL('./editor/index.html');
//$template = new PHPTAL('/home/paskal/public/mytests/www/templ_.html');
// класс Person
class Person
{
public $name;
public $phone;
function Person($name, $phone)
{
$this->name = $name;
$this->phone = $phone;
}
function getName($val)
{
return $val;
示例8: display_tal
private function display_tal(midgardmvc_core_request $request, $content, array $data)
{
$tal = new PHPTAL($request->get_template_identifier());
$tal->setPhpCodeDestination($this->midgardmvc->cache->template->get_cache_directory());
$tal->uimessages = false;
if ($this->midgardmvc->configuration->enable_uimessages) {
if ($this->midgardmvc->uimessages->has_messages() && $this->midgardmvc->uimessages->can_view()) {
$tal->uimessages = $this->midgardmvc->uimessages->render();
}
}
$tal->midgardmvc = $this->midgardmvc;
$tal->request = $request;
// FIXME: Remove this once Qaiku has upgraded
$tal->MIDCOM = $this->midgardmvc;
foreach ($data as $key => $value) {
$tal->{$key} = $value;
}
$tal->setSource($content);
$translator =& $this->midgardmvc->i18n->set_translation_domain($request->get_component()->name);
$tal->setTranslator($translator);
try {
$content = $tal->execute();
} catch (PHPTAL_TemplateException $e) {
throw new midgardmvc_exception("PHPTAL: {$e->srcFile} line {$e->srcLine}: " . $e->getMessage());
}
return $content;
}
示例9: display_tal
private function display_tal($content, $data)
{
// We use the PHPTAL class
if (!class_exists('PHPTAL')) {
require 'PHPTAL.php';
}
// FIXME: Rethink whole tal modifiers concept
include_once 'TAL/modifiers.php';
$tal = new PHPTAL($this->get_cache_identifier());
$tal->uimessages = false;
if ($this->midgardmvc->configuration->enable_uimessages) {
if ($this->midgardmvc->uimessages->has_messages() && $this->midgardmvc->uimessages->can_view()) {
$tal->uimessages = $this->midgardmvc->uimessages->render();
}
}
$tal->midgardmvc = $this->midgardmvc;
// FIXME: Remove this once Qaiku has upgraded
$tal->MIDCOM = $this->midgardmvc;
foreach ($data as $key => $value) {
$tal->{$key} = $value;
}
$tal->setSource($content);
$translator =& $this->midgardmvc->i18n->set_translation_domain($this->midgardmvc->context->component);
$tal->setTranslator($translator);
try {
$content = $tal->execute();
} catch (PHPTAL_TemplateException $e) {
throw new midgardmvc_exception("PHPTAL: {$e->srcFile} line {$e->srcLine}: " . $e->getMessage());
}
return $content;
}
示例10: render
/**
* Returns PHPTAL output - either from a render or from the cache.
*
* @param string|array $template The name of the template to render or
* an array with the ('src') src for a template
* and a ('name') name to help identify the
* template in error messages.
*
* @return string
*/
public function render($template)
{
$this->_checkLoaded();
if ($this->_zendPageCacheContent != false) {
return $this->_zendPageCacheContent;
}
if (!is_array($template)) {
//conversion of template names from '-' split to camel-case
$templateParts = explode('-', $template);
$firstPart = array_shift($templateParts);
foreach ($templateParts as &$currentPart) {
$currentPart = ucfirst($currentPart);
}
$template = $firstPart . implode('', $templateParts);
$this->_engine->setTemplate($template);
} else {
$this->_engine->setSource($template['src'], $template['name']);
}
$this->productionMode = 'production' == APPLICATION_ENV;
$this->_engine->set('doctype', $this->doctype());
$this->_engine->set('headTitle', $this->headTitle());
$this->_engine->set('headScript', $this->headScript());
$this->_engine->set('headLink', $this->headLink());
$this->_engine->set('headMeta', $this->headMeta());
$this->_engine->set('headStyle', $this->headStyle());
if ($this->_purgeCacheBeforeRender) {
$cacheFolder = $this->_engine->getPhpCodeDestination();
if (is_dir($cacheFolder)) {
foreach (new DirectoryIterator($cacheFolder) as $cacheItem) {
if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) {
continue;
}
@unlink($cacheItem->getPathname());
}
}
}
// if a layout is being used and nothing has already overloaded the viewContent,
// register the content as viewContent, otherwise set it to empty
if (!isset($this->viewContent)) {
if ($this->getHelperPath('layout') != false && $this->layout()->isEnabled()) {
$this->_engine->set('viewContent', $this->layout()->content);
} else {
$this->viewContent = '';
}
}
// Strip html comments and compress un-needed whitespace
$this->_engine->addPreFilter(new PHPTAL_PreFilter_StripComments());
if ($this->_compressWhitespace == true) {
$this->_engine->addPreFilter(new PHPTAL_PreFilter_Compress());
}
try {
$result = $this->_engine->execute();
} catch (PHPTAL_TemplateException $e) {
// If the exception is a root PHPTAL_TemplateException
// rather than a subclass of this exception and xdebug is enabled,
// it will have already been picked up by xdebug, if enabled, and
// should be shown like any other php error.
// Any subclass of PHPTAL_TemplateException can be handled by
// the phptal internal exception handler as it gives a useful
// error output
if (get_class($e) == 'PHPTAL_TemplateException' && function_exists('xdebug_is_enabled') && xdebug_is_enabled()) {
exit;
}
throw $e;
}
if ($this->_zendPageCache instanceof Zend_Cache_Core) {
$this->_zendPageCache->save($result, $this->_zendPageCacheKey, array(), $this->_zendPageCacheDuration);
}
return $result;
}
示例11: render
/**
* Returns PHPTAL output - either from a render or from the cache.
*
* @param string|array $template The name of the template to render or
* an array with the ('src') src for a template
* and a ('name') name to help identify the
* template in error messages.
*
* @return string
*/
public function render($template)
{
// Check we are fully configured and initialised.
if ($this->_engine == null) {
throw new \Zend_View_Exception('PHPTAL is not defined', $this);
}
// If a cache has been setup and content is available, return it
if ($this->_zendPageCacheContent != false) {
return $this->_zendPageCacheContent;
}
// Setup the script locations based on the view's script paths
$this->_engine->setTemplateRepository($this->getScriptPaths());
// Do this at this point rather than in the constructor because we don't
// know what the template repositories are going to be at that point.
$this->_engine->addSourceResolver(new PharResolver($this->getScriptPaths()));
// Assign all the variables set here through to the PHPTAL engine.
foreach ($this->getVars() as $key => $value) {
$this->_engine->set($key, $value);
}
if (!is_array($template)) {
$this->_engine->setTemplate($this->_convertTemplateName($template));
} else {
$this->_engine->setSource($template['src'], $template['name']);
}
// Setup a collection of standard variable available in the view
$this->_engine->set('doctype', $this->doctype());
$this->_engine->set('headTitle', $this->headTitle());
$this->_engine->set('headScript', $this->headScript());
$this->_engine->set('headLink', $this->headLink());
$this->_engine->set('headMeta', $this->headMeta());
$this->_engine->set('headStyle', $this->headStyle());
$this->productionMode = 'production' == APPLICATION_ENV;
// If perging of the tal template cache is enabled
// find all template cache files and delete them
if ($this->_purgeCacheBeforeRender) {
$cacheFolder = $this->_engine->getPhpCodeDestination();
if (is_dir($cacheFolder)) {
foreach (new \DirectoryIterator($cacheFolder) as $cacheItem) {
if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) {
continue;
}
@unlink($cacheItem->getPathname());
}
}
}
// if a layout is being used and nothing has already overloaded the viewContent,
// register the content as viewContent, otherwise set it to empty
if (!isset($this->viewContent)) {
if ($this->getHelperPath('layout') != false && $this->layout()->isEnabled()) {
$this->_engine->set('viewContent', $this->layout()->content);
} else {
$this->viewContent = '';
}
}
if (!$this->_preFiltersRegistered) {
// Strip html comments and compress un-needed whitespace
$this->_engine->addPreFilter(new \PHPTAL_PreFilter_StripComments());
if ($this->_compressWhitespace == true) {
$this->_engine->addPreFilter(new \PHPTAL_PreFilter_Compress());
}
$this->_preFiltersRegistered = true;
}
try {
$result = $this->_engine->execute();
} catch (\PHPTAL_TemplateException $e) {
// If the exception is a root PHPTAL_TemplateException
// rather than a subclass of this exception and xdebug is enabled,
// it will have already been picked up by xdebug, if enabled, and
// should be shown like any other php error.
// Any subclass of PHPTAL_TemplateException can be handled by
// the phptal internal exception handler as it gives a useful
// error output
if (get_class($e) == 'PHPTAL_TemplateException' && function_exists('xdebug_is_enabled') && xdebug_is_enabled()) {
exit;
}
throw $e;
}
// If the page needed to be rendered but was configured to
// cache then cache the result of the render.
if ($this->_zendPageCache instanceof \Zend_Cache_Core) {
$this->_zendPageCache->save($result, $this->_zendPageCacheKey, array(), $this->_zendPageCacheDuration);
}
return $result;
}