@baris works now, thanks.
plugin load sequence
-
If I edited a tpl in pluginA and the same tpl in pluginB, which one eventually counts? Can I define such a loading sequence?
-
Plugins should not be modifying templates, only themes should be modifying templates.
You should use an exposed hook, define a custom page, or use jQuery to inject your content on the client-side.
How are you editing the templates? What changes are you trying to make?
-
@yariplus
I made the following plugin: https://github.com/wktang/nodebb-plugin-category-sort-by-votes
It can sort the topics by the votes of their maidPid.
I had to change the sort by panel(add "most_votes" to it). So I had to change the tpl file which arises the issue of loading sequence.If the tpl in persona-theme loads first, all will be fine. But if the persona-theme loads last, my change in this plugin will be overlapped.
-
@yariplus
I am lucky that my plugin loads after the "persona" theme. So it works fine.
But I think lucky should not solve all kinds of problems. -
Instead of replacing the template like you are doing, make your changes to the file at runtime, using the emitter event 'nodebb:ready' like here.
Rename your template to sort-by-votes.tpl so that the original isn't replaced, and only put your changes inside. When the ready event happens, modify the original template by adding your changes to it with a replace(). Like shown here.
-
@xidui yes, you can order the plugins. On ACP -> Extend -> Plugins page there is a "Order Active Plugins" button.
-
Here's a regex you can use for my method above.
-
@yariplus
thanks, I will have a try -
@pichalite
Oh~ thank you -
@pichalite said in plugin load sequence:
@xidui yes, you can order the plugins. On ACP -> Extend -> Plugins page there is a "Order Active Plugins"
That doesnt solve anything most of cases
-
@exodo explain?
-
@pichalite said in plugin load sequence:
@exodo explain?
If a plugin is slow it wont solve to put it first. It will still finish last. Happened to me with many plugins
-
I was wondering about that, the plugins load asynchronously it seems, so what does the order even do?
-
@yariplus hmm I didn't look at the code I just thought it worked that way based on what I read here when this was implemented.
-
based on this... looks like they are loaded in order one after the other...
https://github.com/NodeBB/NodeBB/blob/master/src/plugins.js#L119
-
@pichalite That makes sense, but the app.load hook is still called asynchronous. (each instead of eachSeries)
https://github.com/NodeBB/NodeBB/blob/master/src/plugins/hooks.js#L169
So there is no way to tell if another plugin has finished loading yet.
-
This topic is deceiving though. The plugin load order has nothing to do with the issue. Like I said in my first post,
Plugins should not be replacing default templates, period.
It is ugly, not guaranteed to work, and breaks every other plugin that attempts to do the same.
I already suggested a more sensible system here.
-
@yariplus so, the plugins are registering for the hooks in order but when the hook is fired, they run asynchronously?
-
@pichalite That seems to me to be the case.
-
@yariplus said in plugin load sequence:
@pichalite That seems to me to be the case.
However, the code does not agree -- they are run in series.
They do time out for performance reasons, however. e.g. a static hook will continue with the next listener if the current one takes longer than 2 seconds.