smarty-php / smarty Goto Github PK
View Code? Open in Web Editor NEWSmarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
License: Other
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
License: Other
smarty v.3.1.24
Stack trace:
10 87.0320 22877960 Smarty->fetch( string(17), null, null, null, bool, bool, bool ) .../ViewRenderer.php:84
11 87.0320 22882448 Smarty_Internal_Template->render( bool, bool, bool ) .../Smarty.class.php:824
12 87.0380 22909816 Smarty_Template_Compiled->render( object(Smarty_Internal_Template)[1804] ) .../smarty_internal_template.php:246
13 87.0380 22910424 Smarty_Template_Compiled->process( object(Smarty_Internal_Template)[1804] ) .../smarty_template_compiled.php:199
14 87.0380 22910768 Smarty_Template_Compiled->compileTemplateSource( object(Smarty_Internal_Template)[1804] ) .../smarty_template_compiled.php:152
15 87.0415 22958584 Smarty_Internal_TemplateCompilerBase->compileTemplate( object(Smarty_Internal_Template)[1804], ???, ??? ) .../smarty_template_compiled.php:226
16 87.0434 22966104 Smarty_Internal_SmartyTemplateCompiler->doCompile( string(4272), bool ) .../smarty_internal_templatecompilerbase.php:396
17 87.0689 24537000 Smarty_Internal_Templateparser->doParse( long, string(1) ) .../smarty_internal_smartytemplatecompiler.php:114
18 87.0689 24537584 Smarty_Internal_Templateparser->yy_reduce( long ) .../smarty_internal_templateparser.php:2398
19 87.0689 24537792 Smarty_Internal_Templateparser->yy_r57( ) .../smarty_internal_templateparser.php:2303
20 87.0689 24538008 Smarty_Internal_TemplateCompilerBase->compileTag( string(10), array(0), ??? ) .../smarty_internal_templateparser.php:1585
21 87.0690 24538368 Smarty_Internal_TemplateCompilerBase->compileTag2( string(10), array(0), array(0) ) .../smarty_internal_templatecompilerbase.php:462
22 87.0690 24538416 Smarty_Internal_TemplateCompilerBase->callTagCompiler( string(10), array(0), array(0), ???, ??? ) .../smarty_internal_templatecompilerbase.php:495
23 87.0690 24541352 Smarty_Internal_Compile_Blockclose->compile( array(0), object(Smarty_Internal_SmartyTemplateCompiler)[1814], array(0), null, null ) .../smarty_internal_templatecompilerbase.php:761
Hi,
I made an upgrade from Smarty 3.1.21 to 3.1.27, after this i am getting this error in some templates:
PHP Fatal error: Cannot use [] for reading in /home/conquist/views_c/83c15fae7d6abe30de328afde91cc87c27947c90_0.file.Imovel.view.tpl.php on line 387
The line 387 starts with:
<?php if ((isset($_smarty_tpl->tpl_vars['__foreach_info']->value[]) ? $_smarty_tpl->tpl_vars['__foreach_info']->value[] : null) < 4) {?>
<li><h4><?php echo ('- ').($_smarty_tpl->tpl_vars['info']->value);?>
</h4></li>
<?php }?>`
I am not seeing how to solve this issue. Anybody can help me please?
Edit 1
The original code is:
{foreach $dadosImovel.nomes_diferenciais as $info}
{if $smarty.foreach.info < 4}
<li><h4>{'- '|cat:$info}</h4></li>
{/if}
{/foreach}
While 3.1.23 was ok, since update to 3.1.24 some template are borken
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "smarty/templates/rpmphp/zoom.tpl"
on line 71 "<td>{if $p->repo_main neq $prev}<strong>{$p->repo_main}</strong>{/if}</td>"
too many shorthand attributes <-- thrown in /usr/share/php/Smarty/sysplugins smarty_internal_templatecompilerbase.php on line 71
Looks like a regression.
http://www.smarty.net/docs/en/caching.tpl
there are examples provided how to set cache life time and compile check.
$smarty->setCompileCheck(false);
$smarty->setCacheLifetime(30); // 30 seconds
but those methods don't exist in Smarty class.
checked in smarty v3.1.21
at file https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatebase.php
pls fix
LINE 1: <<<<<< HEAD=====
LINE 862: =======
LINE 1723: >>>>>>> trunk
-This is the default value to output if the variable is empty.
+This is the default value to output if the variable is unset or an empty string
+It does not work for 0 (0 as an integer)/FALSE values as
http://php.net/manual/en/function.empty.php
+Solution to overwrite
http://www.smarty.net/forums/viewtopic.php?p=88776#88776
v.3.1.27 debug popup gives: <i>\r</i><i>\n</i>
as <i>\r</i><i>\n</i>
which exists, when an assigned string ends with a newline (badly).
The sample code is
$tpl->registerFilter('output', function($source, $smarty){
if ($smarty->smarty->isEvalTemplate($smarty->template_resource)) {
return 'Test is passed.';
} else {
return 'Test is failed. Fix strpos in isEvalTemplate() method related to "eval:" string';
}
});
the possible fix is
- if (!empty($template->smarty->registered_filters[$type])) {
+ if (isset($template->smarty->registered_filters[$type])) {
The function _get_filter_name returns wrong name for a closure
It results to
Warning: Illegal offset type to /lib/smarty3/sysplugins/smarty_internal_templatebase.php on line 699
PHP 5.3.29
Version 3.1.25 have strange and randomly errors-warnings .
If I refresh a page for many times, sometime I have this kind of error alert:
Warning: Illegal string offset 'article_title' in E:\madeinwork\petitchefnew\tmp\templates_c\224348b4584ba4e75794f0f5230a0c734d9441c3_0.file.article_ad.tpl.php on line 53
PHP Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "4f51b386251639c28dd52ffe53b55c127b1faa69" on line 1 "{testclose}" unknown tag "testclose" <--
thrown in /nfs/u1404/smarty_test/smarty-3.1.24/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 1
Changing the plugin name to 'testfoo' and the call in the template to {testfoo} provides the expected output.
The older version 3.1.21 allowed {$var.{$index}}. The v. 3.1.24 seems generate error.
Maybe see that not sense to use {$var.{$index}}, because can be just {$var.$index}. I saw that {$var.{$arr.index}} working...
Also, seems to be a problem with "@" used for array functions. I know that not necessary use of # in smarty > 3.1 , but just in vers 3.1.24
When setup:
$smarty->error_reporting = E_ALL;
Showing:
PHP Notice: Undefined index: nocache_hash in .../smarty/libs/sysplugins/smarty_internal_compile_include.php on line 244
The following block of code:
{foreach from=$CUSTOM_QUICK_TASKS item=$task}
<li><a href="{$task.url}">{$task.name}</a></li>
{foreachelse}
<li><a href="?_g=reports&report[date][from]={$QUICK_TASKS.today}&report[date][to]={$QUICK_TASKS.today}">{$LANG.dashboard.task_orders_view_day}</a></li>
<li><a href="?_g=reports&report[date][from]={$QUICK_TASKS.this_weeks}&report[date][to]={$QUICK_TASKS.today}">{$LANG.dashboard.task_orders_view_week}</a></li>
<li><a href="?_g=reports">{$LANG.dashboard.task_orders_view_month}</a></li>
<li><a href="?_g=products&action=add">{$LANG.catalogue.product_add}</a></li>
<li><a href="?_g=categories&action=add">{$LANG.catalogue.category_add}</a></li>
{/foreach}
Is causing a PHP error:
PHP Parse error: syntax error, unexpected '$_smarty_tpl' (T_VARIABLE)
The PHP code generated is:
Notice $foreach_$_smarty_tpl->tpl_vars['task']
<?php
$_from = $_smarty_tpl->tpl_vars['CUSTOM_QUICK_TASKS']->value;
if (!is_array($_from) && !is_object($_from)) {
settype($_from, 'array');
}
$_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value] = new Smarty_Variable;
$_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value]->_loop = false;
foreach ($_from as $_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value]->value) {
$_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value]->_loop = true;
$foreach_$_smarty_tpl->tpl_vars['task']->value_Sav = $_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value];
?>
<li><a href="<?php echo $_smarty_tpl->tpl_vars['task']->value['url'];?>
"><?php echo $_smarty_tpl->tpl_vars['task']->value['name'];?>
</a></li>
<?php
$_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value] = $foreach_$_smarty_tpl->tpl_vars['task']->value_Sav;
}
if (!$_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value]->_loop) {
?>
<li><a href="?_g=reports&report[date][from]=<?php echo $_smarty_tpl->tpl_vars['QUICK_TASKS']->value['today'];?>
&report[date][to]=<?php echo $_smarty_tpl->tpl_vars['QUICK_TASKS']->value['today'];?>
"><?php echo $_smarty_tpl->tpl_vars['LANG']->value['dashboard']['task_orders_view_day'];?>
</a></li>
<li><a href="?_g=reports&report[date][from]=<?php echo $_smarty_tpl->tpl_vars['QUICK_TASKS']->value['this_weeks'];?>
&report[date][to]=<?php echo $_smarty_tpl->tpl_vars['QUICK_TASKS']->value['today'];?>
"><?php echo $_smarty_tpl->tpl_vars['LANG']->value['dashboard']['task_orders_view_week'];?>
</a></li>
<li><a href="?_g=reports"><?php echo $_smarty_tpl->tpl_vars['LANG']->value['dashboard']['task_orders_view_month'];?>
</a></li>
<li><a href="?_g=products&action=add"><?php echo $_smarty_tpl->tpl_vars['LANG']->value['catalogue']['product_add'];?>
</a></li>
<li><a href="?_g=categories&action=add"><?php echo $_smarty_tpl->tpl_vars['LANG']->value['catalogue']['category_add'];?>
</a></li>
<?php
}
?>
After upgrading to 3.1.23 (via composer) I get the following error:
Undefined variable: smarty in sysplugins/smarty_internal_extension_config.php line 136
This appears to be the case if you access an undefined config var:
$smarty.config.my_undefined_var
We're experiencing E_WARNINGS with your unlink operation in smarty_internal_write_file.php:58 on PHP 5.6.3 on Windows, since it is not checking if the file exists.
An is_file wrapper may fixes this:
if (Smarty::$_IS_WINDOWS) {
if (is_file($_filepath)) {
// remove original file
@unlink($_filepath);
}
// rename tmp file
$success = @rename($_tmp_file, $_filepath);
} else {
Full Stack trace:
E_WARNING: unlink(C:\xampp\htdocs\i-doit\src/themes/default/smarty/templates_c\de^ad3fc0693ee80efa44169c025761566a1d4777af.file.searchBar.tpl.php): No such file or directory
... 11 non-project frames
1
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_write_file.php" line 58 in unlink
2
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_write_file.php" line 58 in writeFile
3
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_template.php" line 200 in compileTemplateSource
4
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_templatebase.php" line 149 in fetch
5
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_template.php" line 284 in getSubTemplate
6
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_templatebase.php(151) : eval()'d code" line 40 in content_55361efcc69c05_24852998
7
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_templatebase.php" line 182 in fetch
8
File "C:\xampp\htdocs\i-doit\src\classes\libraries\smarty\libs\sysplugins\smarty_internal_templatebase.php" line 377 in display
9
File "C:\xampp\htdocs\i-doit\src\classes\components\isys_component_template.class.php" line 116 in display
10
File "C:\xampp\htdocs\i-doit\src\hypergate.inc.php" line 265 in include_once
11
File "C:\xampp\htdocs\i-doit\index.php" line 202 in <main>
Hi,
I'm using custom tags and they work unless I use version v3.1.24 o later. Basically, it ignores them.
This would be my settings:
<?php
. . .
$smarty->left_delimiter = '<%';
$smarty->right_delimiter = '%>';
. . .
I've tried the previous release v3.1.23 and has no problem. To be exact, this is the last commit hash that worked: b8eb878
I'll provide a way to test this later in the comments
I've found an interesting error in the compilation of templates in smarty 3.1.21
To reproduce use the following in a template file:
{capture assign="{if true}assign{/if}" name="{if true}name{elseif false}isnt-the-name{/if}"} <div>Do I appear?</div> {/capture} {$assign}
Expected behaviour:
We expect that the capture function should have the following attributes: name=name and assign=assign.
As the template includes {$assign}, we expect that:
<div>Do I appear?</div>
should appear.
Actual behaviour:
Nothing will appear!
The compiled template code mixes up the order of the statements so that the 'if' in the assign attribute is only evaluated if the first if in the name attribute is false.
<?php ob_start();?><?php if (true){?><?php echo "name";?><?php }else{?><?php ob_start();?><?php if (true){?><?php echo "assign";?><?php }?><?php $_$ <div>Do I appear?</div> <?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
The error in compilation occurs:
I am having a problem with upgrading from 3.0 to 3.1, some of our code uses smarty 2 style foreach loops. The comparison of the indexes is breaking.
This works in smarty 3.0 but breaks in 3.1:
{foreach from=['foo', 'bar', 'baz'] key="key" item="value" name="foobar"}
{$smarty.foreach.foobar.index|var_dump}
{if $smarty.foreach.foobar.index > 1}
{$smarty.foreach.foobar.index|var_dump}
{/if}
{/foreach}
Output in 3.0: int(0) int(1) int(2) int(2)
Output in 3.1: int(0) int(1) int(1) int(2) int(2)
I've also noticed that adding brackets around the index is a workaround for the problem.
{if ($smarty.foreach.foobar.index) > 1}
This is probably due to the fact that it compiles to the following code (null > 1
).
Without brackets:
<?php if ((isset($_smarty_tpl->tpl_vars['__foreach_foobar']->value['index']) ? $_smarty_tpl->tpl_vars['__foreach_foobar']->value['index'] : null > 1)) {?>
With brackets:
<?php if ((isset($_smarty_tpl->tpl_vars['__foreach_foobar']->value['index']) ? $_smarty_tpl->tpl_vars['__foreach_foobar']->value['index'] : null) > 1) {?>```
I know this is probably not really a feature, but older versions allowed pre-compiled functions to be used as long as they were in the format:
function smarty_template_function_NAME($_tpl, $params) { ... }
We were able to leverage this prior behavior to hand-optimize template functions and provide standard libraries to work with our multiple projects utilizing Smarty. Below is the patch to I had to add to restore that functionality to sysplugins/smarty_internal_template.php in callTemplateFunction()..
diff smarty_internal_template.php-orig-3.1.24 smarty_internal_template.php 580a581,586 > // HACK - Need to allow pre-compiled functions to be called > if (function_exists($function = 'smarty_template_function_' . $name)) { > $function ($_smarty_tpl, $params); > return; > } > // END HACK
Last version of the Smarty has broken our logic. It renders only last "included template" inside "foreach" cycle. In the example you can see, that template files may be different, but it renders all items as last item.
TEMPLATE
{foreach from=$mapper->getMap() key="fieldKey" item="field"}
<tr>
<td>{$field.name}</td>
<td>{include file="forms/type_{$field.formType}.tpl" fieldName=$fieldKey field=$field}</td>
</tr>
{/foreach}
RESULT ON version 3.2.21 (and it's expected result)
<tr>
<td>name1</td>
<td>
<select id="name1" name="item[name1][]" class="form-control" required="">
<option value="1">Yes</option>
<option value="0">Don't know</option>
<option value="-1">No</option>
</select>
</td>
</tr>
<tr>
<td>name2</td>
<td><input type="text" class="form-control" id="name2" name="item[name2]" value=""></td>
</tr>
<tr>
<td>name3</td>
<td><input type="text" class="form-control" id="name3" name="item[name3]" value=""></td>
</tr>
RESULT ON version 3.2.24 (actual and wrong result)
<tr>
<td>name1</td>
<td><input type="text" class="form-control" id="name3" name="item[name3]" value=""></td>
</tr>
<tr>
<td>name2</td>
<td><input type="text" class="form-control" id="name3" name="item[name3]" value=""></td>
</tr>
<tr>
<td>name3</td>
<td><input type="text" class="form-control" id="name3" name="item[name3]" value=""></td>
</tr>
As I mentioned in title - {php} tags are allowed only in one line. If tag is closed in next line - it causes fatal error.
Hi,
I activated the autoescaping in my Smarty configuration and in some specific cases (if there is no output) a variable is not escaped but just cast to string.
Example :
{$ID='123"><script>alert(\'Yo !\')</script>'}
Url : {url path="/a/b/c/{$ID}"}
$ID is not escaped and it results in a XSS at the end.
Here is the compiled result :
<?php $_smarty_tpl->tpl_vars['ID'] = new Smarty_variable('123"><script>alert(\'Yo !\')</script>', null, 0);?>
URL : <?php echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['url'][0][0]->generateUrlFunction(array('path'=>"/a/b/c/".((string)$_smarty_tpl->tpl_vars['ID']->value)),$_smarty_tpl);?>
url is a helper to retrieve an absolute url and you can see it here if you want : https://github.com/thelia-modules/TheliaSmarty/blob/master/Template/Plugins/UrlGenerator.php#L41
After updating from 3.1.23 to 3.1.25, I get a fatal error like
Fatal error: Call to undefined function smarty_function_testfunc() in C:\path\to\Cache\62\b1\ff\62b1ff3d740b834c8454b925562791706a82261a.view.tpl.php on line 749
This seem to appear when I use a function in my template with the nocache flag like {testfunc nocache}
When I look into the cache file, It isn't even a part of the require / include list. I expected "if (!is_callable('smarty_function_testfunc')) require_once ..."
I use addPluginsDir multiple times (absolute paths only) and use_sub_dirs = true...if that may help
It would be nice to be able to use unless
instead of if
in some occasions
{ unless $hidden }
<div>show me when not hidden</div>
{ /unless }
On line 3456 of vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php there is a syntax error $this->_retvalue = new _smarty_text($this, st);
, which gets triggered in the scenario when PHP tags are allowed, asp tags are off, but an asp-tag <% is found. (We use it for backbone templtes.)
The error message: Use of undefined constant st - assumed 'st'
After upgrading to commit #e9b1f296cb7217b37ac55ed7b2333342a304f295, recommend to fix my previous issue, we are experiencing problems with compiled templates. As soon as we don't use caching/compiled templates, it's all working fine.
SmartyException: Invalid compiled template for '/var/www/newscoop/application/views/scripts/legacy_index.tpl'
in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php line 342
at Smarty_Internal_Template->getRenderedTemplateCode() in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_template_cached.php line 212
at Smarty_Template_Cached->render(object(Smarty_Internal_Template)) in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php line 268
at Smarty_Internal_Template->render(true, false, true) in /var/www/newscoop/vendor/smarty/smarty/libs/Smarty.class.php line 726
at Smarty->fetch('/var/www/newscoop/application/views/scripts/legacy_index.tpl', null, null, null, true) in /var/www/newscoop/vendor/smarty/smarty/libs/Smarty.class.php line 740
SmartyException: Invalid compiled template for '_tpl/header.tpl'
in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php line 342
at Smarty_Internal_Template->getRenderedTemplateCode() in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_template_cached.php line 212
at Smarty_Template_Cached->render(object(Smarty_Internal_Template)) in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php line 268
at Smarty_Internal_Template->render(true, false, true) in /var/www/newscoop/vendor/smarty/smarty/libs/Smarty.class.php line 726
at Smarty->fetch('_tpl/header.tpl', null, null, null, true) in /var/www/newscoop/vendor/smarty/smarty/libs/Smarty.class.php line 740
at Smarty->display('_tpl/header.tpl') in /var/www/newscoop/include/smarty/campsite_plugins/function.render.php line 84
at smarty_function_render(array('file' => '_tpl/header.tpl'), object(Smarty_Internal_Template)) in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_cacheresource_custom.php(144) : eval()'d code line 1574
at content_550aa9402cb130_71307622(object(Smarty_Internal_Template)) in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php line 351
at Smarty_Internal_Template->getRenderedTemplateCode() in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_template_cached.php line 212
at Smarty_Template_Cached->render(object(Smarty_Internal_Template)) in /var/www/newscoop/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php line 268
at Smarty_Internal_Template->render(true, false, false) in /var/www/newscoop/vendor/smarty/smarty/libs/Smarty.class.php line 726
Hello,
I assume the following scenario:
I have many template directories, when each contains template.html file. Let's assume these directories have names: directory1, directory2, directory3.
Then we add all these directories using Smarty::addTemplateDir() method in exact above order to template directories list.
I'd like to be able to create templates as below:
I'd like to get as the result the following text:
This is the test.
Now Smarty triggers error in such scenario, because of recursive template loading.
It could detect that a given directory has been used as template directory for template.html file already and continue searching for template.html file from next template directory in directory chain. It would allow to create dynamically modified templates with simple usage from php code:
$smarty->display('template.html');
This code could be used by something like application plugins.
Maybe you have another solution for described scenario?
Bests, Tomasz
Server : Debian
Version php : 5.5.15
Version Smarty : 3.1.24
Code TPL :
{if $page.module == $moduleCourant
and ($page.page == $pageCourante )
and ($page.action == '' or $page.action == $actionCourante)
}
....
{/if}
Error :
Parse error: syntax error, unexpected '(' in /srv/scm/*/*/app/storage/templates_compil/442cd046018da1e81e070092bdba8ed93b254f84_0.file.header.tpl.php on line 213
TPL compil :
<?php if ($_smarty_tpl->tpl_vars['page']->value['module'] == $_smarty_tpl->tpl_vars['moduleCourant']->value($_smarty_tpl->tpl_vars['page']->value['page'] == $_smarty_tpl->tpl_vars['pageCourante']->value)($_smarty_tpl->tpl_vars['page']->value['action'] == '' || $_smarty_tpl->tpl_vars['page']->value['action'] == $_smarty_tpl->tpl_vars['actionCourante']->value)) {?>
it lacks the condition : and
Please forgive my clumsy English .
where it was set as follows in composer.json, since version 3.1.23 has been installed , I have been recognized as this is the latest stable version.
"require": {
"smarty / smarty": "~ 3.1"
}
However , errors that did not occur in version 3.1.21 has occurred .
PHP Fatal error: Access to undeclared static property: Smarty :: $ _ IS_WINDOWS in .....
Since there is no way , I have specified to use the 3.1.21 to composer.json.
"require": {
"smarty / smarty": "3.1.21"
}
Do not the people who have the same problem ?
Example template data:
$data = [
'rows' => [[], ['children' => ['bug appears here']], []]
];
Example template file:
{foreach $rows as $row}
{$row@index},
{if !empty($row.children)}
{foreach $row.children as $children}
{* anything *}
{/foreach}
{/if}
{/foreach}
Output:
0, 1, 1,
Should be:
0, 1, 2,
Example:
{if isset($abc.sub)
and $abc.sub
and isset($def)
and $def and !isset($bla)}
{/if}
In 3.1.21 is template compiled without any problems
if (isset($_smarty_tpl->tpl_vars['abc']->value['sub'])&&$_smarty_tpl->tp...
In 3.1.24 looks like something breaks the compiling - && is missing:
if (isset($_smarty_tpl->tpl_vars['abc']->value['sub'])$_smarty_tpl->tpl_va....
Working examples on 3.1.21 and 3.1.24
{if isset($abc.sub) and $abc.sub and isset($def) and $def and !isset($bla)}{/if}
It also works if 'and' is replaced with &&
{if isset($abc.sub)
&& $abc.sub
&& isset($def)
&& $def and !isset($bla)}
{/if}
smarty-foreach-test.php
<?php
header("Content-Type: text/plain");
$smarty = new Smarty();
// Do your smarty setup
$array = array(
array(
"var" => "Parent 1 var",
"sub" => array(
array("var" => "Sub 1 var"),
array("var" => "Sub 2 var")
)
),
array(
"var" => "Parent 2 var",
"sub" => array(
array("var" => "Sub 1 var"),
array("var" => "Sub 2 var")
)
),
);
$smarty->assign("array", $array);
$smarty->display("smarty-foreach-test.tpl");
smarty-foreach-test.tpl
Test 1: No Nested {literal}{foreach}{/literal}
---------------------------
{foreach $array as $item}
{$item@iteration}: {$item.var} <--- Note @iteration (sequential, as expected)
{if $item@last}
Last! (parent)
{/if}
{/foreach}
Test 2: With Nested {literal}{foreach}{/literal}
-----------------------------
{foreach $array as $item}
{$item@iteration}: {$item.var} <--- Note @iteration (not sequential)
{foreach $item.sub as $sub}
{$sub@iteration}: {$sub.var}
{if $sub@last}
Last! (sub)
{/if}
{/foreach}
{if $item@last}
Last! (parent)
{/if}
{/foreach}
^--- Note the lack of the "Last! (parent)"
Output
Test 1: No Nested {foreach}
---------------------------
1: Parent 1 var <--- Note @iteration (sequential, as expected)
2: Parent 2 var <--- Note @iteration (sequential, as expected)
Last! (parent)
Test 2: With Nested {foreach}
-----------------------------
1: Parent 1 var <--- Note @iteration (not sequential)
1: Sub 1 var
2: Sub 2 var
Last! (sub)
3: Parent 2 var <--- Note @iteration (not sequential)
1: Sub 1 var
2: Sub 2 var
Last! (sub)
^--- Note the lack of the "Last! (parent)"
You are providing a tar.gz which has the string DEV in it's version number instead of 3.1-24.
in Smarty.class.php:
Another typo:
This TPL code works with all versions up to 3.1.21:
<?xml version="1.0" encoding="{$modules.Language->getString('html_encoding')}" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="{$modules.Language->getString('html_direction')}" lang="{$modules.Language->getLangCode()}" xml:lang="{$modules.Language->getLangCode()}">
3.1.21 outputs
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="de-DE" xml:lang="de-DE">
3.1.24 outputs
<?xml version="1.0" encoding="{$modules.Language->getString('html_encoding')}" standalone="no" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="de-DE" xml:lang="de-DE">
It basically ignores the first variable?!
will be compiled to
but ->value[sid] is missing a " ' ", it should be ->value['sid']
Smarty 3.1.23 broke php 5.2 compatability. the documentation still says its php 5.2+ compatible, but the source coude uses anonymus function in
Fatal error occured #4 syntax error, unexpected T_FUNCTION in ...\vendor\smarty\smarty\libs\sysplugins\smarty_internal_compile_private_php.php on line 57
either the documentation needs fixing either the 57 line needs to be changed to a callback
{if $smarty.const.SEA_IS_P_NAME === true && $f.p_id}
//...
{/if}
compiled to
<?php if (@constant(''SEA_IS_P_NAME'')===true&&$_smarty_tpl->tpl_vars['f']->value['p_id']) {?>
//...
<?php }?>
error: PHP Parse error: syntax error, unexpected 'SEA_IS_P_NAME' (T_STRING)
''
- is two single quotes.
Hi,
I'm currently in version 3.1.19 and I use the inheritance system of Smarty for extending my templates.I'm using a global layout which is extended by each template.
In this layout I have "blank" or default block and I override them in my page. For example the title page.
in the layout.tpl (the global layout) :
{block name="check-auth"}
{check_auth role="ADMIN" resource="{block name="check-resource"}{/block}" module="{block name="check-module"}{/block}" access="{block name="check-access"}{/block}" login_tpl="/admin/login"}
{/block}
check_auth is a custom function I wrote as a smarty plugin and in each template page I override the check-resource and check-module block with a template-specific value.
in my page :
{block name="check-resource"}admin.order{/block}
{block name="check-access"}update{/block}
in version 3.1.19 of smarty, the first block will be compiled like this :
<?php ob_start();?>admin.order<?php $_tmp1=ob_get_clean();?>
in 3.1.21 :
<?php ob_start();
admin.order
$_tmp1=ob_get_clean();?>
There is obviously a syntax error.
I think this is a regression, it seems you change the way smarty compiles the template, I have less compiled files in version 3.1.21 than in version 3.1.19
Did you already fix this in master branch ?
Thanks
PHP Warning: addslashes() expects parameter 1 to be string, array given in
.../smarty/libs/sysplugins/smarty_internal_extension_codeframe.php
on line 56.
After e312dd9.
case : $_template->parent->source->filepath is "/a/b/c/../../d/e/abc.tpl"
$path = dirname($_template->parent->source->filepath);
...
$path = str_replace(array('', './'), array('/', ''), $path);
$path
result : "/a/b/c/..d/e/" <= wrong value
expect : "/a/b/c/../../d/e/"
modify
$path = dirname($_template->parent->source->filepath);
=>
$path = realpath(dirname($_template->parent->source->filepath));
$path
result : "/a/d/e/" <= right value
i see this issue in 3.1.21
[Thu Apr 30 06:37:41.557259 2015] [:error] [pid 8687] [client 10.128.1.1:34038] PHP Notice: Use of undefined constant st - assumed 'st' in /usr/local/lib/php/Smarty/sysplugins/smarty_internal_templateparser.php on line 3456,
Server version: Apache/2.4.6 (CentOS)
PHP 5.4.16 (cli) (built: Oct 31 2014 12:59:36)
short tags enabled
anything else???
Example:
// test.php
require '../libs/Smarty.class.php';
$smarty = new Smarty;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
$smarty->assign('arr', ['first' => 10]);
$smarty->display('test.tpl');
// the template file: test.tpl
{if $arr.second = $arr.first + 100 nocache}
{$arr.first} - {$arr.second}
{/if}
Error as follows:
PHP Notice: Undefined index: first in /home/bryce/git/smarty/demo/cache/77fd09ff9079054983b57cce4b84650d9500fb25.test.tpl.php on line 32
PHP Stack trace:
PHP 1. {main}() /home/bryce/git/smarty/demo/index.php:0
PHP 2. Smarty->display() /home/bryce/git/smarty/demo/index.php:33
PHP 3. Smarty->fetch() /home/bryce/git/smarty/libs/Smarty.class.php:838
PHP 4. Smarty_Internal_Template->render() /home/bryce/git/smarty/libs/Smarty.class.php:824
PHP 5. Smarty_Internal_Template->getRenderedTemplateCode() /home/bryce/git/smarty/libs/sysplugins/smarty_internal_template.php:275
PHP 6. content_555b17606a6182_39500260() /home/bryce/git/smarty/libs/sysplugins/smarty_internal_template.php:371
PHP Notice: Undefined index: first in /home/bryce/git/smarty/demo/cache/77fd09ff9079054983b57cce4b84650d9500fb25.test.tpl.php on line 33
PHP Stack trace:
PHP 1. {main}() /home/bryce/git/smarty/demo/index.php:0
PHP 2. Smarty->display() /home/bryce/git/smarty/demo/index.php:33
PHP 3. Smarty->fetch() /home/bryce/git/smarty/libs/Smarty.class.php:838
PHP 4. Smarty_Internal_Template->render() /home/bryce/git/smarty/libs/Smarty.class.php:824
PHP 5. Smarty_Internal_Template->getRenderedTemplateCode() /home/bryce/git/smarty/libs/sysplugins/smarty_internal_template.php:275
PHP 6. content_555b17606a6182_39500260() /home/bryce/git/smarty/libs/sysplugins/smarty_internal_template.php:371
- 100
Maybe this is not allowed originally.>_<
Hi,
This sequence {$form_act.contents|count+1} generate error.
... " - Unexpected "+", expected one of: "
<<
I tried and {$form_act.contents|@count+1} , but same error.
Finally I saw that working with round brackets: {($form_act.contents|count)+1}
Google AppEngine PHP Environment uses paths like:
/base/data/home/apps/s~[project-name]/[module]:[version]/[path]/template.tpl
example:
/base/data/home/apps/s~myproject/default:1.316876871687/templates/template.tpl
The function Smarty_Resource::parseResourceName in libs\sysplugins\smarty_resource.php uses this code to determine resource type:
public static function parseResourceName($resource_name, $default_resource)
{
$parts = explode(':', $resource_name, 2);
if (!isset($parts[1]) || !isset($parts[0][1])) {
// no resource given, use default
//...
and when we have this type of path, the explode(':' splits the $resource_name incorrectly.
It's possible to change the delimiter or escape the path?
Thanks
The composer.json file mentions only >=php-5.2, but the use of mb_convert_encoding
in e.g. libs/plugins/modifier.escape.php
requires the mbstring extension. This does actually cause a problem at runtime for me, and it goes away when PHP is recompiled.
https://github.com/smarty-php/smarty/commits/master
Uwe's git usage is ridicious. Why make pull request for each commit? PR should be made if there's something to review and someone to review and the changeset is not trivial!
There are plenty of documentation available on internet of best practices including github not just git itself.
Hi,
My code works in 3.1.24, but gets the following error in 3.1.25:
[Wed Jun 17 10:45:31 2015] PHP Fatal error: Maximum execution time of 30 seconds exceeded in
/Users/Xavier/xProjects/time-track/.dist/local/20150617T084453Z/vendor/
smarty/smarty/libs/sysplugins/smarty_internal_resource_file.php on line 131
[Wed Jun 17 10:45:31 2015] 127.0.0.1:58693 [500]: /php/login.php - Maximum execution time of 30 seconds exceeded in
/Users/Xavier/xProjects/time-track/.dist/local/20150617T084453Z/vendor/
smarty/smarty/libs/sysplugins/smarty_internal_resource_file.php on line 131
My code is:
initialize.php
$smarty = new Smarty();
$smarty->use_sub_dirs = false;
$smarty->setTemplateDir("$lib/smarty/templates");
$smarty->setCompileDir("$lib/smarty/templates_c");
$smarty->addPluginsDir("$lib/smarty/plugins");
login.php
, I require_once initialize.php
then// lots of $smarty->assign
$smarty->display('login.tpl');
I have replaced login.tpl
with a very basic html text (no php, no tags), and I still get the timeout.
Any idea what could be the issue?
Also, the smarty.net site seems down
{function name='select'}
{foreach from=$options item='label' key='key'}
{if is_array($label)}
{if !empty($label)}
{select options=$label}
{/if}
{elseif $key == $value}
{$label|escape}
{/if}
{/foreach}
{/function}
{select options=$options}
When I don't have compiled template I get unknown tag "select"
error
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.