Where is the template parsing logic?
-
I can't find decent documentation for it anywhere.
Looked under here https://nodebb.readthedocs.io/en/latest/themes/templates.html,
here https://github.com/NodeBB/NodeBB/blob/master/src/middleware/render.js,All I found was the logic that injects partial templates into each other here https://github.com/NodeBB/NodeBB/blob/master/src/meta/templates.js
But as far as the parsing goes I'm clueless.
What I'm trying to accomplish:
- access parent category's siblings within a .tpl file.
- understand how the pathing logic (eg: {../name}) works
- If the pathing logic is interchangeable with the basic (only?) true/false logic (eg <!-- IF children.length --> ...)
- Once all the questions above are answered, Extend the parsing logic.
- Find a right place to ask these kind of questions.
Thanks
-
not sure about most of your questions but the templating engine can be found here https://github.com/psychobunny/templates.js
-
@Qwertyzw Maybe one could not parse it's parent and siblings within a tpl file.:rage1:
-
The way the template engine works is it takes the data sent to it (handled by NodeBB). You can see this data by navigating to the corresponding
/api
route. For example, the api route for this topic: https://community.nodebb.org/api/topic/10163/where-is-the-template-parsing-logicFrom inside of a
<!-- BEGIN -->..<!-- END -->
you can reference values in that array object with../
.e.g.
{ foobar: [ { baz: 'quux' }, { baz: 'test' } ] }
and...
<!-- BEGIN foobar --> this is the value of baz: {../baz} <!-- END foobar -->
-
@julian what if I'd like to create an helper for the template system in my plugin?
This is what's written on GitHub:
templates.registerHelper('print_is_human', function(data, iterator, numblocks) { return (data.isHuman) ? "Is human" : "Isn't human"; }); <!-- BEGIN animals --> {function.print_is_human} <!-- END animals --> prints out: Isn't human Isn't human Is human
So I just do something like
res.registerHelper('myhepler', function(data, iterator, numblocks) { return (data.myValue) ? "It is my value" : "It isn't my value"; }); <!-- BEGIN values --> {function.myhelper} <!-- END values -->
?
-
-
@jiangcaiyang I meant to say siblings, the (misleading?) path syntax '../' lead me to saying parent's siblings. I don't mean parsing them either, I only intend to reference them.