本文整理汇总了PHP中Smarty::createTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty::createTemplate方法的具体用法?PHP Smarty::createTemplate怎么用?PHP Smarty::createTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty
的用法示例。
在下文中一共展示了Smarty::createTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get the evaluated contents of the view.
*
* @param string $path
* @param array $data
* @return string
*/
public function get($path, array $data = array())
{
$template = $this->smarty->createTemplate($path);
$template->assign($this->smarty->getTemplateVars());
$template->assign($data);
return $template->fetch();
}
示例2: render
public function render($name, array $values = array())
{
if (defined('ENV_DEV')) {
//$this->engine->clearCacheFiles();
//$this->engine->clearTemplateCache();
$this->engine->clearAllCache();
$this->engine->clearCompiledTemplate();
}
$template = $this->engine->createTemplate($name . $this->suffix);
$template->assign($values);
return $template->fetch();
}
示例3: isCached
/**
* test if cache is valid
*
* @param string|object $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @return boolean cache status
*/
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
if ($template === null && $this instanceof $this->template_class) {
return $this->cached->valid;
}
if (!$template instanceof $this->template_class) {
if ($parent === null) {
$parent = $this;
}
$template = $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
}
// return cache status of template
return $template->cached->valid;
}
示例4: setUp
public function setUp()
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$this->_template = $smarty->createTemplate('string:');
$this->_template->assignGlobal('render', $render);
}
示例5: msginitString
/**
* Inspect the supplied source, capture gettext references as a PoFile object.
*
* @param string $source php source code
* @param string $refname source identification used for PO reference comments
*
* @return PoFile
*/
public function msginitString($source, $refname)
{
if (!$this->poFile instanceof PoFile) {
$this->poFile = new PoFile();
}
$tpl = $this->smarty->createTemplate('eval:' . $source);
$tags = $this->smarty->getTags($tpl);
$translateTags = array_merge($this->gettextTags, $this->pgettextTags, $this->ngettextTags);
foreach ($tags as $tag) {
if (in_array($tag[0], $translateTags)) {
$entry = new PoEntry();
$haveEntry = false;
$entry->add(PoTokens::REFERENCE, $refname);
foreach ($tag[1] as $temp) {
foreach ($temp as $key => $value) {
if ($value[0] == "'" || $value[0] == '"') {
if (in_array($key, $this->msgidArgNames)) {
$entry->set(PoTokens::MESSAGE, $this->escapeForPo($value));
$haveEntry = true;
} elseif (in_array($key, $this->msgidPluralArgNames)) {
$entry->set(PoTokens::PLURAL, $this->escapeForPo($value));
} elseif (in_array($key, $this->msgctxtArgNames)) {
$entry->set(PoTokens::CONTEXT, $this->escapeForPo($value));
}
}
}
}
if ($haveEntry) {
$this->checkPhpFormatFlag($entry);
$this->poFile->mergeEntry($entry);
}
}
}
return $this->poFile;
}
示例6: setUp
public function setUp()
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$this->_template = $smarty->createTemplate('string:');
$this->_template->assignGlobal('render', $render);
$this->_menuData = [['label' => 'Label 1', 'page' => 'CM_Page_Example', 'params' => ['foo' => 1]], ['label' => 'Label 2', 'page' => 'CM_Page_Example', 'params' => ['foo' => 2]]];
}
示例7: testRender
public function testRender()
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$template = $smarty->createTemplate('string:');
$template->assignGlobal('render', $render);
$this->assertSame($render->getUrlResource('layout', 'foo'), smarty_function_resourceUrl(array('path' => 'foo', 'type' => 'layout'), $template));
$this->assertSame($render->getUrlStatic('foo'), smarty_function_resourceUrl(array('path' => 'foo', 'type' => 'static'), $template));
}
示例8: testBackgroundImageData
public function testBackgroundImageData()
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$template = $smarty->createTemplate('string:');
$template->assignGlobal('render', $render);
$html = '<img src="https://example.com/img/foo.png" style="background-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)" class="background-cover" width="456" height="123" />';
$this->assertSame($html, smarty_function_img(['path' => 'https://example.com/img/foo.png', 'width' => 456, 'height' => 123, 'background-image' => 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'], $template));
}
示例9: _createSelect
/**
* @param array $params
* @return CM_Dom_NodeList
*/
private function _createSelect(array $params)
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$template = $smarty->createTemplate('string:');
$template->assignGlobal('render', $render);
$html = smarty_function_select($params, $template);
return new CM_Dom_NodeList($html);
}
示例10: compileAllTemplates
/**
* Compile all template files
*
* @param string $extension template file name extension
* @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
*
* @return integer number of template files compiled
*/
public static function compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
{
// switch off time limit
if (function_exists('set_time_limit')) {
@set_time_limit($time_limit);
}
$smarty->force_compile = $force_compile;
$_count = 0;
$_error_count = 0;
// loop over array of template directories
foreach ($smarty->getTemplateDir() as $_dir) {
$_compileDirs = new RecursiveDirectoryIterator($_dir);
$_compile = new RecursiveIteratorIterator($_compileDirs);
foreach ($_compile as $_fileinfo) {
$_file = $_fileinfo->getFilename();
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
if (!substr_compare($_file, $extension, -strlen($extension)) == 0) {
continue;
}
if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
$_template_file = $_file;
} else {
$_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
}
echo '<br>', $_dir, '---', $_template_file;
flush();
$_start_time = microtime(true);
try {
$_tpl = $smarty->createTemplate($_template_file, null, null, null, false);
if ($_tpl->mustCompile()) {
$_tpl->compileTemplateSource();
$_count++;
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
flush();
}
} catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "<br><br>";
$_error_count++;
}
// free memory
$smarty->template_objects = array();
$_tpl->smarty->template_objects = array();
$_tpl = null;
if ($max_errors !== null && $_error_count == $max_errors) {
echo '<br><br>too many errors';
exit;
}
}
}
return $_count;
}
示例11: testRender
public function testRender()
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$template = $smarty->createTemplate('string:');
$template->assignGlobal('render', $render);
$contentExpected = $render->getLayoutFile('resource/img/favicon.svg')->read();
$contentActual = smarty_function_resourceFileContent(array('path' => 'img/favicon.svg'), $template);
$this->assertGreaterThan(0, strlen($contentActual));
$this->assertSame($contentExpected, $contentActual);
}
示例12: testRenderCrossSite
public function testRenderCrossSite()
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$siteOther = $this->getMockSite('CM_Site_Abstract', null, ['urlCdn' => 'http://cdn.other.com']);
$renderOther = new CM_Frontend_Render(new CM_Frontend_Environment($siteOther));
$template = $smarty->createTemplate('string:');
$template->assignGlobal('render', $render);
$this->assertSame($renderOther->getUrlResource('layout', 'foo'), smarty_function_resourceUrl(array('path' => 'foo', 'type' => 'layout', 'site' => $siteOther), $template));
$this->assertSame($renderOther->getUrlStatic('foo'), smarty_function_resourceUrl(array('path' => 'foo', 'type' => 'static', 'site' => $siteOther), $template));
}
示例13: setUp
public function setUp()
{
$smarty = new Smarty();
$this->_render = new CM_Frontend_Render();
$this->_template = $smarty->createTemplate('string:');
$this->_template->assignGlobal('render', $this->_render);
$language = CMTest_TH::createLanguage();
$language->setTranslation('.date.period.years', '{$count} years', ['count']);
$language->setTranslation('.date.period.hour', '1 hour');
$language->setTranslation('.date.period.day', '1 day');
}
示例14: setUp
public function setUp()
{
$smarty = new Smarty();
$render = new CM_Frontend_Render();
$formMock = $this->getMockForAbstractClass('CM_Form_Abstract', array(), '', true, true, true, array('getAction'));
$actionMock = $this->getMockForAbstractClass('CM_FormAction_Abstract', array($formMock), '', true, true, true, array('getName'));
$actionMock->expects($this->any())->method('getName')->will($this->returnValue('Create'));
$formMock->expects($this->any())->method('getAction')->will($this->returnValue($actionMock));
/** @var CM_Form_Abstract $formMock */
$render->getGlobalResponse()->treeExpand(new CM_Frontend_ViewResponse($formMock));
$this->_template = $smarty->createTemplate('string:');
$this->_template->assignGlobal('render', $render);
}
示例15: testRender
public function testRender()
{
$smarty = new Smarty();
$template = $smarty->createTemplate('string:');
$this->assertContainsAll(['div', 'data-foo="3"', 'data-bar="baz"', 'foo bar'], smarty_function_tag(['el' => 'div', 'content' => 'foo bar', 'data' => ['foo' => 3, 'bar' => 'baz']], $template));
$exception = $this->catchException(function () use($template) {
smarty_function_tag(['content' => 'foo bar'], $template);
});
$this->assertInstanceOf('ErrorException', $exception);
$this->assertContains('Param `el` missing.', $exception->getMessage());
$exception = $this->catchException(function () use($template) {
smarty_function_tag(['el' => 'span', 'data' => 'foo bar'], $template);
});
$this->assertInstanceOf('ErrorException', $exception);
$this->assertContains('Param `data` should be an array.', $exception->getMessage());
}