Forum Discussion

SheryBulos's avatar
5 years ago

dynamic change when changing freemarker variable ?

Hello everyone,
kindly, how should I change the content of freemarker variable dynamically?

when clicking on the button the id of the macro change so the displayed question changes
how could I achieve this? 

<#macro question questions id>
        - name is ..... ${questions[id].name}
        - Question is ...${questions[id].text}
        - next question is .. ${questions[id].next}
       <button onclick="changeContent(id = ${questions[id].next})"></button>
</#macro>
<@question questions=q.questions id="q1"/>


q =
<questions>
     <q1>
         <name>who?</name>
         <text>who are you ?</text>
         <next>q1</next>
    </q1>
    <q2>
        <name>how</name>
        <text>how are you ?</text>
         <next>q1</next>
    </q2>
</questions>

kind regards,
Shery
RaniaWael 

  • FreeMarker is handled on the server side in order to generate the HTML that will be sent to the user. Once the page has been generated, FreeMarker is no longer relevant. So if you want to do scripted interaction like having a clickable button, that would involve JavaScript rather than FreeMarker.

    If you want JS that can switch between visible items, then the data for all the items would need to be sent in the HTML, and you could use CSS to hide the inactive items. Any state about which items are visible would be known in JavaScript and manipulated, e.g., by adding and removing classes.

2 Replies

  • AndrewF's avatar
    AndrewF
    Khoros Oracle
    5 years ago

    FreeMarker is handled on the server side in order to generate the HTML that will be sent to the user. Once the page has been generated, FreeMarker is no longer relevant. So if you want to do scripted interaction like having a clickable button, that would involve JavaScript rather than FreeMarker.

    If you want JS that can switch between visible items, then the data for all the items would need to be sent in the HTML, and you could use CSS to hide the inactive items. Any state about which items are visible would be known in JavaScript and manipulated, e.g., by adding and removing classes.