Conditional template possible


  • Anime Lovers

    use-case

    1. In the template, there are 2 transaction types (html select), namely: withdrawal and deposit.
    2. Based on the selection, the form will be rendered with the relevant fields while non-relevant fields will be hidden:
      2a. User select withdrawal, the withdrawal relevant fields will be shown.
      2b. User select deposit, 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.


  • Community Rep

    This is something you would use client-side js/jQuery to accomplish and not templates.


  • Translator

    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.


  • Anime Lovers

    @yariplus and @jarey, thanks I got your points.

    haha I was looking for shortcut. I just read on this templates.js, it seem powerful, so I was looking around for more examples to see how far it can go.

    With jquery, I can listen to the change in the <select> and render the fields accordingly.


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.