• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Conditional template possible

Scheduled Pinned Locked Moved Technical Support
4 Posts 3 Posters 2.1k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Bruce LeeB Offline
    Bruce LeeB Offline
    Bruce Lee Anime Lovers
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
  • yariplusY Offline
    yariplusY Offline
    yariplus Community Rep
    wrote on last edited by
    #2

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

    https://jsfiddle.net/hk6Lddg3/

    1 Reply Last reply
    1
  • jareyJ Offline
    jareyJ Offline
    jarey Translator
    wrote on last edited by jarey
    #3

    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.

    1 Reply Last reply
    0
  • Bruce LeeB Offline
    Bruce LeeB Offline
    Bruce Lee Anime Lovers
    wrote on last edited by
    #4

    @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.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development