[RFC] Global template variable for user avatar

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
User avatar
A_Jelly_Doughnut
Registered User
Posts: 1780
Joined: Wed Jun 04, 2003 4:23 pm

Re: [RFC] Global template variable for user avatar

Post by A_Jelly_Doughnut » Mon Apr 23, 2012 11:29 pm

naderman wrote:(new template feature to access array elements?)
Yay for syntactic sugar. More interesting problem is how do you assign an array to the template engine?
A_Jelly_Doughnut

User avatar
AliasM2K
Registered User
Posts: 82
Joined: Tue Mar 27, 2012 2:33 am

Re: [RFC] Global template variable for user avatar

Post by AliasM2K » Tue Apr 24, 2012 12:18 am

Nice idea! +1 :)

By the way, I think avatar is not necessary while posting :D

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC] Global template variable for user avatar

Post by naderman » Fri Jul 20, 2012 9:53 pm

A_Jelly_Doughnut wrote:
naderman wrote:(new template feature to access array elements?)
Yay for syntactic sugar. More interesting problem is how do you assign an array to the template engine?
Just like any other variable, just assign an array rather than a string. Just can't loop over it currently as that needs a special call.

Either way, anyone up to implementing this with or without array assignment to templates? Please create a ticket and pull request, would love to see this in 3.1 :)

User avatar
psoTFX
Registered User
Posts: 1984
Joined: Tue Jul 03, 2001 8:50 pm
Contact:

Re: [RFC] Global template variable for user avatar

Post by psoTFX » Sat Jul 21, 2012 2:12 am

Maybe ... I have it "kinda" working but need a little more time and ofc feedback.

User avatar
psoTFX
Registered User
Posts: 1984
Joined: Tue Jul 03, 2001 8:50 pm
Contact:

Re: [RFC] Global template variable for user avatar

Post by psoTFX » Sat Jul 21, 2012 2:24 pm

http://tracker.phpbb.com/browse/PHPBB3-11013

So - this all looks deceptively simple ... I'm sure I've missed something here :D Anyway I've modified the filter and associated elements to do as per Nils and others suggestion. You can assign an entire array to a template variable and retrieve it via the following syntax:

{<TEMPLATE VAR>:<element name>}

I used : instead of . because I felt the . syntax suggested a "block", it's much of a muchness and the regexp's easily modified for whatever. This works for block level elements:

{<block>.<TEMPLATE VAR>:<element name>}

and conditionals:

<!-- IF <TEMPLATE VAR>:<element name> <condition> -->

Back to the original OP's request - assigning of various user->data values to the template. While we could just dump $user->data to the template as a whole things like avatars, ranks and the like will need to be specifically set won't they? e.g. a call to get_user_avatar() and the like. So should these things be assigned individuality to the template, e.g. {USER_AVATAR}, {USER_RANK}, or assigned to this new array solution, e.g. {USER_DATA:avatar}, {USER_DATA:rank} or some such? Or something else entirely of course ...

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC] Global template variable for user avatar

Post by naderman » Sat Jul 21, 2012 2:44 pm

Should we maybe use -> rather than : then to be more in line with PHP? The colon seems like entirely new syntax, which I haven't ever seen in any language.

I think that if we want to pass that info on every request anyway, we might want to just put it in $user->data? And then assign that array in whole?

User avatar
psoTFX
Registered User
Posts: 1984
Joined: Tue Jul 03, 2001 8:50 pm
Contact:

Re: [RFC] Global template variable for user avatar

Post by psoTFX » Sat Jul 21, 2012 7:54 pm

Okay, made the change to -> and I agree that or perhaps [] makes more sense a colon just sprang to mind :D Anyway, ticket is 11013. As I say this is deceptively simple and I'm bound to have missed something obvious, just know it ...

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC] Global template variable for user avatar

Post by naderman » Sun Jul 22, 2012 12:09 am

Hm, -> or [] - anyone else have a preference? [] Might seem a bit more natural to someone working on styles. E.g. form elements use that syntax and it's js array syntax too.

ecwpa
Registered User
Posts: 181
Joined: Mon Jan 24, 2005 2:10 am
Contact:

Re: [RFC] Global template variable for user avatar

Post by ecwpa » Sun Jul 22, 2012 12:25 am

For template variables? Those would look like this {user->avatar} or {user[avatar]} right? I'm ok with the second.
Slightly better English than it was in 2005, still improving :D

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC] Global template variable for user avatar

Post by naderman » Sun Jul 22, 2012 2:28 am

Well they are all uppercase so {USER->AVATAR} or {USER[AVATAR]}

Post Reply