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

$this pointer instead of e.g. $smarty.foreach.name.varname
Goto page Previous  1, 2
 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Sep 15, 2004 4:56 pm    Post subject: Reply with quote

%% was deprecated to keep the template syntax simple, thus keep compiling simple. It may get removed altogether at some point. I'm not adverse to using $_ though, that doesn't add a new var syntax. It also has the variable naming convention of a "private" variable, which makes sense in this case.

I'm still not fond of requiring a new parameter on the section function, internal var references should be automatic and consistant.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Sep 15, 2004 5:56 pm    Post subject: Reply with quote

Okay.

Just to add another idea: maybe we could add a switch/option using a new class member variable to decide if we should automatically create internal private vars for various structures. Perhaps $auto_private_var = true or even $auto_private_var_prefix="_". In the latter case, if null or empty, then use don't auto create vars others prefix the name with the given text. For example, I might choose $auto_private_var_prefix="this_" and in template:

{section name="foo" loop=$bar}
{$this_foo.index}

I guess I would just like to avoid any assumptions on Smarty's part in terms of the namespace.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Sep 15, 2004 6:18 pm    Post subject: Reply with quote

no more config-options please. and especially no config-options that affect template-syntax or semantics.

if you want a shortcut to your section-properties, I'd call it assign:
{section name=foo assign=foo loop=3}{$foo.index}{/section}
(maybe we could make the name optional in that case)

the same would work for {foreach} then.

a case of precedence is {capture}:
{capture name=foo}...{/capture}{$smarty.capture.foo}
was there, and
{capture assign=foo}...{/capture}{$foo}
was added later for convience.
i think this is a little comparable to what you have in mind with section.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Sep 15, 2004 6:24 pm    Post subject: Reply with quote

messju wrote:
no more config-options please. and especially no config-options that affect template-syntax or semantics.


Why? Its not the same as a PHP config since it is completely with the user's control.

Never-the-less, I somewhat agree with your reasoning. Its just that "assign" doesn't seem to make as much sense here as it does in something like capture. Still, it is probably the best suggestion yet.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Sep 15, 2004 7:14 pm    Post subject: Reply with quote

messju wrote:
if you want a shortcut to your section-properties, I'd call it assign.


"assign" makes me think the output of the section loop gets assigned to the variable, which would be a good assumption if the use of assign was consistant (which would be desirable?)

So, I vote for either introducing $_, or just drop it altogether and continue to use the already available $smarty.* variables.
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Sep 15, 2004 7:54 pm    Post subject: Reply with quote

[quote="mohrt"]
messju wrote:
So, I vote for either introducing $_, or just drop it altogether and continue to use the already available $smarty.* variables.


my vote goes for the latter of the two above Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Sep 15, 2004 8:40 pm    Post subject: Reply with quote

Alas. Well, then not using "name" but rather using "alias" or "this" or one of the other suggestions seems appropriate to me. I'm willing to let it go, though....

But riddle me this: why isn't $_smarty_vars pre-populated with the appropriate keys to act as placeholders for the various values it can hold?Something along the lines of:

$_smarty_vars = array('section'=>array(), 'foreach'=>array(), ....);

The reason I ask is because without that little detail I think it makes my alias plugin idea kinda moot since I can't bind to an element that doesn't exist.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Sep 23, 2004 12:46 am    Post subject: Reply with quote

For me, the worst thing about section is the way that the name property is used in-template. I find the following (standard!) syntax very non-intuitive and not inline with variable handling everywhere else in Smarty:
Code:
{section name=tr loop=Links}
   {$Links[tr]}
{/section}

I think it would be more obvious if that were:
Code:
{$Links[$tr]}


My point is that it is more than just getting a short-cut to $smarty.section.varname -- there is an opportunity to clean-up the syntax (@monte: I'm -1 for introducing new syntax quirks on this one). I would even go far as to say to hell with BC and propose what I think is most obvious (and also the main thrust of this thread so far Smile)

Code:
{$Links[$tr.index]}


No new attributes, no pretending to try to accomodate every old template. On the other hand, I would leave the existing syntax but I would propose that it be deprecated.
Back to top
View user's profile Send private message
tibuda
Smarty n00b


Joined: 15 Apr 2007
Posts: 1

PostPosted: Sun Apr 15, 2007 10:45 pm    Post subject: Reply with quote

Quote:
Posted: Wed Sep 22, 2004 9:46 pm

Sorry for the necroposting, but I wish to know if this is already implemented.
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 -> Feature Requests All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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