Search code examples
freemarker

Freemarker - assign expression within quotes


How to put ${expression} within double quotes like this?

for example:<User name="" >

I tried with following but it doesn't work:

<User name="${expression}" > get evaluation error

<User name="${r"${expression}"}" > get <User name="${expression}" >, not the assigned value

Thanks.


Solution

  • You can use ?html

      <Table name="${expression?html}" >
    

    Or auto-escaping mechanism

    <#ftl output_format="HTML">
    

    This built-in is deprecated by the auto-escaping mechanism introduced in 2.3.24

    Or escape

    <#escape x as x?html>
      <Table name="${expression}" >
    </#escape>