1

Is it possible to change a variable in ISML without showing it?

Here is what I tried:

<isset name="sessionVar" value="${1}" scope = "session"/>
${session.custom.sessionVar} <br/>
${session.custom.sessionVar += 1} <br/>
${session.custom.sessionVar} <br/>

And here is the output:

1.0 
2.0 
2.0 

As we can see the variable did actually change, but it was shown twice, while I would like it to be shown once.

Here is the solution which gives me a desired output:

<isset name="sessionVar" value="${1}" scope = "session"/>
${session.custom.sessionVar} <br/>
<isset name="sessionVar" value="${session.custom.sessionVar += 1}" scope = "session"/>
<iscomment> ${session.custom.sessionVar += 1} <br/> </iscomment> 
${session.custom.sessionVar} <br/>

And here is the output for the solution:

1.0 
2.0 

As we can see the solution works, but it is a crutch. That is because the semantic of the isset is broken, because the isset is designed to declare a variable, but not to modify one.

So, is there at least a solution to my problem, which is not a crutch?

Thank you.

1 Answer 1

1

It's discouraged to do business logic within templates. But yes, you can do scripting without output. To do so, just wrap your code with <isscript></isscript> eg:

<isscript>
  var foo = 0;
  foo++;
</isscript>
${foo}

outputs:

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .