Reply to Re: [SMARTY] Smarty and constants

Your name:

Reply:


Posted by Erik Schmitt on 07/14/05 10:16

Am Mittwoch, 13. Juli 2005 17:24 schrieb boots:
> --- Erik Schmitt <e.schmitt@e-novum.com> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация