sample.freemarker2.txt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <#ftl stripText=false>
  2. <#-- Free marker demo -->
  3. <#comment>
  4. This demonstrates the FreeMarker language. The default theme is not very
  5. colorful and displays many different token types in the same color, but keep in
  6. mind that you can define your own theme (or extend an existing one).
  7. Note that free marker actually defines 6 similar but different syntax modes:
  8. - 3 tag syntax modes: Angle (<#if>), Bracket ([#if]), and Auto.
  9. - 2 interpolation modes: Dollar (${...}) and Bracket ([=...])
  10. In auto mode, the first tag determines the tag syntax. You can use the language
  11. IDs "freemarker.tag-bracket.interpolation-dollar" etc. to force a specific mode.
  12. The default FreeMarker mode is Angle/Dollar.
  13. </#comment>
  14. <#macro greet name>
  15. <font size="+2">Hello ${name}!</font>
  16. </#macro>
  17. <#macro border>
  18. <table border=4 cellspacing=0 cellpadding=4><tr><td>
  19. <#nested>
  20. </tr></td></table>
  21. </#macro>
  22. <#function avg x y>
  23. <#return (x + y) / 2>
  24. </#function>
  25. <#assign user = "Juila Smith">
  26. <#assign animals = [{"name": "Tanuki", "price": 200}, {"name": "Phoenix", "price": 1111}]>
  27. <html>
  28. <head>
  29. <title>Welcome!</title>
  30. </head>
  31. <body>
  32. <#-- Greet the user with his/her name -->
  33. <h1>
  34. <@greet user />
  35. </h1>
  36. <p>We have these animals:
  37. <ul>
  38. <#list animals as animal>
  39. <li>${animal.name} for ${animal.price} Euros
  40. </#list>
  41. </ul>
  42. <@border>The bordered text</@border>
  43. The average of 35 and 49 is ${avg(35, 49)}.
  44. </body>
  45. </html>