-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template call #1414
base: development
Are you sure you want to change the base?
Template call #1414
Conversation
See: http://www.elkarte.net/community/index.php?topic=1077 Signed-off-by:Joshua Dickerson <[email protected]>
Every template called through loadSubTemplate() now has hooks. You should be able to change almost everything in a theme without overwriting a single file. Signed-off-by:Joshua Dickerson <[email protected]>
3/4 of the way done with changing all of the template calls and I realized that there is no point in returning anything but it will break things when you do echo template_call('some_template'); because it call_integration_hook() returns an array. Signed-off-by:Joshua Dickerson <[email protected]>
…_call() Signed-off-by:Joshua Dickerson <[email protected]>
…alled, the array won't be empty. Signed-off-by:Joshua Dickerson <[email protected]>
Apparently travis complains. |
I brokeded it
Templates with references won't work when called with template_call()
Signed-off-by:Joshua Dickerson <[email protected]>
Is there a specific reason why you added both a __pre and a __execute? |
Initially they had return values. So the __pre() would have a different return value. __execute's return value changes whether it will execute or not. I guess there is no reason to have a pre and an execute now, but call __execute() with a return value could stop the execution of the template, so be careful. |
AHA!
TBH my idea of the templating in general was a bit different (i.e. build a list of templates to be executed in a certain order and let it run, something like the layers), but I have to admit the idea of call_template is quite good and should give a lot more flexibility than mine. TL;DR I wouldn't use Yep, what I wanted to say with |
The reason I wouldn't want it to be a different call is because the plugin/event system should handle it the same. The name of the event is what differentiates it. No matter how you do it, the template system has the power to run PHP. If that's what people want to do with the templates, it will happen. Take a look at what I'm doing with the event system https://gist.github.com/joshuaadickerson/9347177 to see the direction I'm working it to. |
Of course the template is php and anyone using it has already a lot of freedom, but to me there is a difference between "listen, since you can already do almost anything, feel free to do it, I don't care" and "here is the thing: you could do this, we highly discourage this behaviour and we set this limit, if you want to kill yourself, feel free, but don't complain with us if tomorrow it doesn't work". For example, to load a template file there is a special function loadTemplate that is called way before any template functions are called. As far as I have always understood the theory should be:
As I said I may be badly wrong. ;) |
You're totally right, that's all the template should do. However, since On Tue, Mar 4, 2014 at 11:12 AM, emanuele45 [email protected]:
|
I just thought about something. Using the event system is wrong here. The listener needs to know what the theme is so you don't call it for every theme. Then again, as an admin or developer, you might want the event to be triggered on every theme. That seems like a lot of administrative work. |
This makes templates infinitely pluggable by adding in 3 events for every template: pre, execute, post. You can effectively add before/after or not even call any/every template which makes themes very extensible.
It changes all calls of every template to use template_call()
If a template doesn't use template_call() it doesn't break anything so there are no backwards compatibility issues.
Although it can be added at any time, I'd still recommend some testing and code review to make sure I didn't miss anything or break anything.
See http://www.elkarte.net/community/index.php?topic=1077 for the discussion
Resubmitted to development branch from: #1403