thanks!
all good now.
I hadn't noticed that the header.tpl template had been changed here:
https://github.com/NodeBB/nodebb-theme-persona/commit/90a1ba1eb1f5377c45c44656d3172389656c5a90
templates.parse can be used by passing a file name as the first param, but I don't think you need to pass the .tpl extension. At least that's how it's used in core. Once it parses it passes back html which we then add to DOM using jquery.
@baris So if I understand I need to do all of this in a front script. My problem is that I want to use
categories.getCategoriesByPrivilege(app.uid, 'find', function(err, data){}
I think I can use require to actually use categories but I won't have the app.uid
info which is needed. Or is there a way to use this in front scripts ?
Tell me if I'm wrong but I see the solution like this :
My only question is how can you use parsing function in front file ? module is not defined so templates = module.parent.require('templates.js')
wont work is there another way to call this function ?
Thanks for your help.
@esiao good question, @psychobunny recently removed the templates.js from core so it is a npm module now, not sure how it is used from client side right now. Will wait for him to chime in on that.
In my lib I get the data object provided by categories.getCategoriesByPrivilege
I use res to send it to some /api/ address
In a front script I retrieve this data
I use the parse function to transform it in html
I append it using Jquery
This sounds right.
There should be a global object attached to the window called templates
(same with app
and ajaxify
, some methods in there could be useful to you as well)
Also the template is automatically loaded for you as well in the same step.
templates.parse(template, data, callback);
@psychobunny, @baris Thank you I'll try that out tommorow. Going to sleep
@psychobunny window.ajaxify.loadTemplate
is broken. Object window.ajaxify returns it as a function but when in use there's a Uncaught TypeError: undefined is not a function
error.
And console.log(window.ajaxify.loadTemplate) returns undefined.
@Schamper has the same problem with his plugin cards : https://community.nodebb.org/topic/2495/so-the-acp-doesn-t-work-on-master/7
While I don't think I need it cause templates.parse do the same job I wanted to see what you meant by using ajaxify
works for me, although as you say, templates.parse is what you should be using instead, ajaxify.loadTemplate will be changed to a private function eventually
window.ajaxify.loadTemplate('login', function(data) {
console.log(data);
});
this works for me, it will explode if
A- your template doesn't exist or in your case
B- you don't pass the template string in
I've managed to do what I wanted to do, thanks for your help
@psychobunny said in How to show a widget in a theme widget area ?:
window.ajaxify.loadTemplate
This isn't the case anymore, rite? Any other ways to expose ajaxify
to scripts in the custom header?
Cheers.
Answer to self: enable the custom header and the global vars will be there. Sounds about right?