Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Variable with constant name [Solved]

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
dioobr
Smarty n00b


Joined: 16 Jan 2016
Posts: 2

PostPosted: Sat Jan 16, 2016 12:35 am    Post subject: Variable with constant name [Solved] Reply with quote

I migrated from version 3.1.19 to 3.1.29 and found a great little problem. My code looked like this:

Code:
$smarty->assign('tx', ['ex' => ex, 'uv' => uv];


ex and uv are constant.

How is the template:

Code:
<div>{$tx.ex} - {$tx.uv}</div>


After migration, the following message/error appears:

Code:
Notice:  Undefined index: tx in /www/smarty/templates_c/d97eba2f0985c71e7b13f7a661c1daebc0a5039b_0.file.home.tpl.php on line 99


This is a bug? This is no longer allowed? What should I do?

Thanks!


Last edited by dioobr on Sat Jan 16, 2016 1:49 am; edited 2 times in total
Back to top
View user's profile Send private message
dioobr
Smarty n00b


Joined: 16 Jan 2016
Posts: 2

PostPosted: Sat Jan 16, 2016 1:48 am    Post subject: Reply with quote

This is probably the most stupid question, whose solution is obvious: use the constant as a variable in the template.

Quote:
<div>{ex} - {uv}</div>


Done.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Jan 16, 2016 8:00 am    Post subject: Reply with quote

That notice would only make sense, if you are using tx when it is not assigned to template. I.e. some code path is going around your assignment, but still render the same template.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Jan 27, 2016 10:21 pm    Post subject: Reply with quote

Since a while you can use constants directly in templates.

This could create some ambiguity when using the {$foo.bar} syntax for array access and bar but bar is also a constant.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP