Inserting additional template data into composer template
-
Hi, I am customizing the default composer.
To have a better understanding of how this templating system works, I am trying to add a new variable, similar to
isTopicOrMain
for a conditonal in the composer.tpl.I noticed that
isTopicOrMain
is defined in 2 fileslibrary.js
, in line:197, inside objecttemplateData
composer.js
in line:457, inside objectdata
when are each definition used?
From the look it seems one is for server side and the other one is client side? Are the two object synchronized at some point then?Thank you.
-
@erichbb direct links to the code:
nodebb-plugin-composer-default/library.js at 921837c20b38540c36e219a4c526b43d23ace858 · NodeBB/nodebb-plugin-composer-default
Default Composer for NodeBB. Contribute to NodeBB/nodebb-plugin-composer-default development by creating an account on GitHub.
GitHub (github.com)
nodebb-plugin-composer-default/static/lib/composer.js at 921837c20b38540c36e219a4c526b43d23ace858 · NodeBB/nodebb-plugin-composer-default
Default Composer for NodeBB. Contribute to NodeBB/nodebb-plugin-composer-default development by creating an account on GitHub.
GitHub (github.com)
Yes one is server side and one is client side.
-
@erichbb I think this might help you:
howto: inject hidden data into composer?
@yariplus Nice! I will explore other features first while waiting for the merge and release. Yes, got your point that "anything on the client is modifiable" :).
NodeBB Community (community.nodebb.org)
Of course your fields don't need to be hidden. But with this example and editing composer you should be able to add fields to composer as default. Hidden as well as visible.
-
@pitaj
when does that server side code (filterComposerBuild
method) runs?Specifically, I know it is binded to the hook
filter:composer.build
method I do not know when does that hook fires.
I have put someconsole.log()
statements inside thefilterComposerBuild
method, but I can't find the output from either brower's debug console or nodebb backend terminal (running in./node dev
).
And from the name of the method, it seems it is only executed once when the composer initializing?Which hook should I bind to if I want react to interaction? (Or are hooks only relevant for server side stuff?)
Thanks.
-
@dogs Thanks.
Can you point me to some materials explaining how the frontend and hooks interact?
I don't complete follows their discussion ondata.submittedData
and is still confused about which variable is the post data stored in and which hooks are involved when it is passed around.Edit:
Also found this, maybe relevant
Difference between templateValues and templateData