|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ilyalyu Smarty Regular
Joined: 03 Nov 2009 Posts: 72
|
Posted: Tue Mar 13, 2012 12:47 pm Post subject: Bug: $smarty.const inside string |
|
|
Latest Smarty version from SVN
Code: | PHP:
define('my_const', '1');
Smarty:
{$smarty.const.my_const}
{"{$smarty.const.my_const}"}
Output:
1
@my_const
Expected output:
1
1 |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Mar 13, 2012 6:11 pm Post subject: |
|
|
This was a sideefect of yesterdays fix.
The SVN trunk is updated again. |
|
Back to top |
|
ilyalyu Smarty Regular
Joined: 03 Nov 2009 Posts: 72
|
Posted: Wed Mar 14, 2012 8:06 am Post subject: |
|
|
Thx |
|
Back to top |
|
shoty Smarty n00b
Joined: 28 Jan 2015 Posts: 1
|
Posted: Wed Jan 28, 2015 12:19 pm Post subject: behavior changed in r4582 |
|
|
in revision 4582 (string) cast was added to variables. (Revision comment: - correction of yesterdays bugfix (Forum Topic 21175 and 21182))
I have a function like this:
Code: | {reorder key="{$order_key}" by="company_id" label={language key="partner"} filter="list" filterlist="{$companies}"} |
The $companies variable is an array. It used to work in older version (3.1.2).
In 3.1.21 no loger works.
Old compiled code:
Code: | <?php echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['reorder'][0][0]->smarty_reorder(array('key'=>($_smarty_tpl->tpl_vars['order_key']->value),'by'=>"company_id",'label'=>$_tmp1,'filter'=>"list",'filterlist'=>($_smarty_tpl->tpl_vars['companies']->value)),$_smarty_tpl);?> |
New compiled code:
Code: | <?php echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['reorder'][0][0]->smarty_reorder(array('key'=>((string)$_smarty_tpl->tpl_vars['order_key']->value),'by'=>"company_id",'label'=>$_tmp1,'filter'=>"list",'filterlist'=>((string)$_smarty_tpl->tpl_vars['companies']->value)),$_smarty_tpl);?> |
How can I pass that variable as an array ?
If I remove the quotes from variable still doesn't work.
Compiled code for this try:
Code: | <?php ob_start();?><?php echo $_smarty_tpl->tpl_vars['companies']->value;?>
<?php $_tmp2=ob_get_clean();?><?php echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['reorder'][0][0]->smarty_reorder(array('key'=>((string)$_smarty_tpl->tpl_vars['order_key']->value),'by'=>"company_id",'label'=>$_tmp1,'filter'=>"list",'filterlist'=>$_tmp2),$_smarty_tpl);?> |
I just realised that if I also remove the { and } arround $companies variable it works as expected. It's just an unexpected behavior change and I have to verify a lot of template files to change this kind of code! I will let this comment here for others. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jan 28, 2015 12:48 pm Post subject: |
|
|
You were using a bug. The {$var} syntax casts the variable as string for printing in the document.
As you've discovered yourself, if you use variable directly, as you should, you have the expected functionality. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Jan 29, 2015 7:02 pm Post subject: |
|
|
Attribute specifications like
is always bad syntax.
Template variables must be passed like
This syntax does work for all variable types.
Only if you want embed a string variable into another string you can use something like
Code: | foo = "my name is {$name}" |
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Jan 29, 2015 10:23 pm Post subject: |
|
|
U.Tews wrote: | Only if you want embed a string variable into another string you can use something like
Code: | foo = "my name is {$name}" |
|
Even then, it's a bad juju… |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|