After the reply of PayBas, which is correct, I updated my previous post in this topic. Not sure what changing the $template means.
Hmm, couldn't you pass the $template variable to your template event handler? ...assuming you use $template as a service so there is no need for globals.
core.posting_modify_template_vars correction
Re: core.posting_modify_template_vars correction
Also, we don't want to render a template in our extension, we want to use the existing template event.
Re: core.posting_modify_template_vars correction
Didn't see your reply.
$template is the template object that renders the template and to which variables/data is assigned. We just need a way to set our own variables to the template, relying on the service injecting the template also isn't ideal, because then the $template gets injected to the constructor every single time, regardless of whether or not our event fires. This event is only on the posting page, so why inject the template any other time? That just confuses things, especially since there are other core template modification events that do exactly what is advertised, so why is this one so different?
By "template event" we mean an <!-- EVENT --> being called in the template that simply includes another piece of HTML/template, not a PHP event.
The flow:
- posting page loads
- template is assigned variables (the forum name, etc..)
- core event fires with the current state of the template obj (or the array): we add additional variables to the template
- the template is rendered
- a template event fires: our template file is included making use all the variables assigned to the template
$template is the template object that renders the template and to which variables/data is assigned. We just need a way to set our own variables to the template, relying on the service injecting the template also isn't ideal, because then the $template gets injected to the constructor every single time, regardless of whether or not our event fires. This event is only on the posting page, so why inject the template any other time? That just confuses things, especially since there are other core template modification events that do exactly what is advertised, so why is this one so different?
By "template event" we mean an <!-- EVENT --> being called in the template that simply includes another piece of HTML/template, not a PHP event.
The flow:
- posting page loads
- template is assigned variables (the forum name, etc..)
- core event fires with the current state of the template obj (or the array): we add additional variables to the template
- the template is rendered
- a template event fires: our template file is included making use all the variables assigned to the template
Re: core.posting_modify_template_vars correction
Can you give a concrete example please?rfdy wrote:[...], especially since there are other core template modification events that do exactly what is advertised, so why is this one so different?[...]
And for the rest, i don't understand what is the problem if you get a dependence that you don't always use?
I think that the events should give only the "special" vars and not any unique public service that everyone can retrieve through the DI.
Member of the phpBB Development-Team
No Support via PM
No Support via PM
Re: core.posting_modify_template_vars correction
You make it sound like a contradiction, but we are basically saying the same thing .rfdy wrote:We don't want to change the $template itself. We just want to assign more variables to it, so that our template event handler has access to them. Isn't that the point of the event, to modify the assigned variables before they get assigned?
Re: core.posting_modify_template_vars correction
Sorry to drag on this conversation, but the point is that the changes made by adding those additional variables to the event really doesn't help anybody if the one variable they need access to needs to be passed into the constructor. Events should be constructed in a way such that you're given all the local details you need at that moment, not rely on some global functionality (the $template service is just a fancy word for a global variable). All the other core events with "modify" in their name allow you to modify the data directly without additional constructor dependencies, however in this case the variables that are being sent with the event don't affect the template at all, hence the confusion with the name of the event. It's good that you're breaking the event vars, but changing those variables doesn't affect the template, because they're already assigned (unless they're assigned by reference, which just adds more confusion and isn't a desirable effect).
For now I will add the template to the constructor, even though my eight other events in that class don't need it and clutters up the code with additional dependencies making it harder to test.
For now I will add the template to the constructor, even though my eight other events in that class don't need it and clutters up the code with additional dependencies making it harder to test.
Re: core.posting_modify_template_vars correction
bump, would be very interested to hear opinions on last post
Re: core.posting_modify_template_vars correction
I reread all your posts, but I think we still need a concrete example of what you are trying to do (the actual use-case). I just can't get a clear idea of what your perceived problem is.
It's late, so please excuse me if I'm ignorant or misunderstood you.
It's late, so please excuse me if I'm ignorant or misunderstood you.
Re: core.posting_modify_template_vars correction
This thread isn't actually relevant anymore since the changes we requested were eventually made some time after beta 3.