开发者

Can a freemarker interpolation contain an interpolation?

开发者 https://www.devze.com 2022-12-26 19:51 出处:网络
Let\'s say I have Freemarker variable A that contains the name of another variable on the hash tree, say. \"B.\" I\'d like to use a to read the value of B so, for example, if B contained \"C\" I could

Let's say I have Freemarker variable A that contains the name of another variable on the hash tree, say. "B." I'd like to use a to read the value of B so, for example, if B contained "C" I could tell Free开发者_JAVA百科marker to output C using A: ${${A}} should result in the output of "C". Naturally, this doesn't work in Freemarker, but is there a way to accomplish this?


Use the .vars special variable, which is a hash (map) of the variables, and hence you can use the aHash[aKeyExpression] syntax:

${.vars[A]}

via Daniel Dekany, documentation author & maintainer

0

精彩评论

暂无评论...
验证码 换一张
取 消