Search code examples
mvel

How to assign a variable in MVEL Template


I would like to assign variables in an mvel template.

Assuming that my template has only a property foo defined, I would like to do the following:

@{bar=foo}
@{bar.name}

Unfortunately this outputs me the toString() of foo and then the property name of bar. I would like to do the same but without printing anything with the assignation.


Solution

  • (just in case anyone lands here...)

    According to this documentation, you can use @code blocks to execute statements without emitting output.

    @code{bar=foo}
    @{bar.name}