Is it at all possible to extract blocks out of $template, so they can be manipulated by the extension before being reassigned?
Trying to override the breadcrumbs functionality, but that function sets template variables directly.
This kind of stuff happens in a few places and is very difficult to code around, where arrays are assigned to $template directly, rather than calling an event before they are assigned. Similar to the core.viewtopic_get_post_data event, which doesn't give access to the template variables before they are assigned. (very frustrating!).
Thanks!
how to extract variables out of $template?
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.
If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.
If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
- DavidIQ
- Customisations Team Leader
- Posts: 1905
- Joined: Thu Mar 02, 2006 4:29 pm
- Location: Earth
- Contact:
Re: how to extract variables out of $template?
Yes. You can iterate through
https://github.com/DavidIQ/phpBB-ReIMG- ... _reimg.php
$template->_tpldata
to get what you need. Maybe this might help:https://github.com/DavidIQ/phpBB-ReIMG- ... _reimg.php
Re: how to extract variables out of $template?
Thanks! I'll try it soon.
Re: how to extract variables out of $template?
Just tried this out and it didn't work.
print_r($template->_tpldata); results in: Undefined property: phpbb/template/twig/twig::$_tpldata
Any other suggestions?
print_r($template->_tpldata); results in: Undefined property: phpbb/template/twig/twig::$_tpldata
Any other suggestions?
Re: how to extract variables out of $template?
I don't think this still works now 3.1 uses twig.DavidIQ wrote:Yes. You can iterate through$template->_tpldata
to get what you need. Maybe this might help:
https://github.com/DavidIQ/phpBB-ReIMG- ... _reimg.php
Re: how to extract variables out of $template?
it is still possible, you just need to retrieve the template_context service:
https://github.com/phpbb/area51-phpbb3/ ... hp#L66-L68
https://github.com/phpbb/area51-phpbb3/ ... hp#L66-L68
Member of the phpBB Development-Team
No Support via PM
No Support via PM
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: how to extract variables out of $template?
alter_block_array is probably what you're looking for.
Re: how to extract variables out of $template?
Using alter block with the breadcrumbs for example is cumbersome. It was much easier to just destroy the entire "navlinks" block and recreate it.
Mentioned this before, but: events should really be called with template array data before it is assigned to the template.
Mentioned this before, but: events should really be called with template array data before it is assigned to the template.
Re: how to extract variables out of $template?
Propose changes and events in those situations in a PR or RFC here. For example: https://github.com/phpbb/phpbb/pull/1915/files#diff-3rfdy wrote:Is it at all possible to extract blocks out of $template, so they can be manipulated by the extension before being reassigned?
Trying to override the breadcrumbs functionality, but that function sets template variables directly.
This kind of stuff happens in a few places and is very difficult to code around, where arrays are assigned to $template directly, rather than calling an event before they are assigned. Similar to the core.viewtopic_get_post_data event, which doesn't give access to the template variables before they are assigned. (very frustrating!).
Thanks!
Has an irascible disposition.
Re: how to extract variables out of $template?
We did exactly that. And was strongly rejected. The event included "modify template" in its name, yet the array was assigned to the template before the event was called. Our suggestion to fix that was denied claiming we should use "global $template". We found a way around our initial request, but other events still contain the same basic issue.
We have some general concerns over the events system as a whole. Our feeling is that they are not being carefully considered before they are added, which will create major issues going forward as any event once in 3.1-stable will probably not change until 3.2-stable as it'll break backwards compatibility. That is, once the events are added, refactoring becomes very difficult if not impossible without changing the way events behave.
We have some general concerns over the events system as a whole. Our feeling is that they are not being carefully considered before they are added, which will create major issues going forward as any event once in 3.1-stable will probably not change until 3.2-stable as it'll break backwards compatibility. That is, once the events are added, refactoring becomes very difficult if not impossible without changing the way events behave.