Conditional template possible
-
use-case
- In the template, there are 2 transaction types (html select), namely:
withdrawal
anddeposit
. - Based on the selection, the form will be rendered with the relevant fields while non-relevant fields will be hidden:
2a. User selectwithdrawal
, the withdrawal relevant fields will be shown.
2b. User selectdeposit
, similar the deposit relevant fields will be shown.
Is it possible to do the above in template?
I have read up on https://docs.nodebb.org/en/latest/themes/templates.html and https://github.com/psychobunny/templates.js but I cannot find similar example on it.
Please advise, thanks.
- In the template, there are 2 transaction types (html select), namely:
-
This is something you would use client-side js/jQuery to accomplish and not templates.
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
(jsfiddle.net)
-
As @yariplus said you can do this by having all the fields rendered by the template and then showing/hiding them with javascript logic.
Another way is to use a parameter and fefresh the page so the template can apply the conditional logic based on the parameter. At least coming from java background thats possible using jsps, should be doable without problem here too.
But the js way is the most convenient IMHO.
-