Yay for syntactic sugar. More interesting problem is how do you assign an array to the template engine?naderman wrote:(new template feature to access array elements?)
[RFC] Global template variable for 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
A_Jelly_Doughnut
Re: [RFC] Global template variable for user avatar
Nice idea! +1
By the way, I think avatar is not necessary while posting
By the way, I think avatar is not necessary while posting
Re: [RFC] Global template variable for user avatar
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.A_Jelly_Doughnut wrote:Yay for syntactic sugar. More interesting problem is how do you assign an array to the template engine?naderman wrote:(new template feature to access array elements?)
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
Re: [RFC] Global template variable for user avatar
Maybe ... I have it "kinda" working but need a little more time and ofc feedback.
Re: [RFC] Global template variable for user avatar
http://tracker.phpbb.com/browse/PHPBB3-11013
So - this all looks deceptively simple ... I'm sure I've missed something here 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 ...
So - this all looks deceptively simple ... I'm sure I've missed something here 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 ...
Re: [RFC] Global template variable for user avatar
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?
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?
Re: [RFC] Global template variable for user avatar
Okay, made the change to -> and I agree that or perhaps [] makes more sense a colon just sprang to mind Anyway, ticket is 11013. As I say this is deceptively simple and I'm bound to have missed something obvious, just know it ...
Re: [RFC] Global template variable for user avatar
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.
Re: [RFC] Global template variable for user avatar
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
Re: [RFC] Global template variable for user avatar
Well they are all uppercase so {USER->AVATAR} or {USER[AVATAR]}