Re: [SMARTY] Smarty and constants
Erik Schmitt <[email protected]>
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Organization | eNovum GmbH |
| Message-ID | <[email protected]> |
Am Mittwoch, 13. Juli 2005 17:24 schrieb boots: > --- Erik Schmitt <[email protected]> wrote: > > Hello, > > Hi. > > > recently I asked how to access constants in a dynamic way. > > The solution is to use > > > > {$smarty.config.$bla} instead of {#$bla#}. > > > > But in my case $bla is the result of calling an > > object method. Hence I have to write: > > > > {assign var="bla" value=$myObject->myMethod()} > > {$smarty.config.$bla} > > > > Somethink like {$smarty.config.`$myObject->myMethod()`} > > does not work. > > > > On the other hand, smarty will stop with a syntax error > > if it finds a leading $ like in {#$bla#}. So what about > > simply allowing smarty to evaluate the "content" if it starts > > with a $? > > > > (In my case, the methods are returning IDs for strings in > > a language files, with some of the IDs stored in a DB). > > > > What do you think? > > You may be interested in the following thread at the forum: > > http://www.phpinsider.com/smarty-forum/viewtopic.php?t=3806 > > Basically, it affords a way to decouple dynamic lookups without adding > new syntax or magic, eg: > > {$myObject->myMethod()|lookup:$smarty.config} > > xo boots Hello, thanks for the link. I think I will use a lookup that works per default on the $smarty.config array. {$myObject->myMethod()|constant} I am not sure what is meant by the term "magic", I am not a very experienced developer; do you mean that smarty would have to evaluate $myObject->myMethod() in {#$myObject->myMethod()#} ? In the templates a lot of {#bla#} statements will be used and to me it would look a lot more visually consistent to the designer to allow {#$bla#}. Plus, a new programmer needs to know only what the expression {#($)constant#} means or how it works: It is not easy to see at a first glance that {$myObject->myMethod()|lookup:$smarty.config} just works on the same array as {#constant#} does. It is not clear that the source of the result is the same. From my point of view, allowing and evaluating {#$bla#} means not to invent new syntax but reducing complexity in the templates (hence bugs) and leads to easier maintanance efforts (hence less costs). (I am aware that of course this would be a new syntactical element, but I reagard it more as an variant of an already existing one. I am also aware that the reduced complexity in the template would then be shifted over to the Smarty-engine, but that is what engines are made for.) Thanks! Erik -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php