FreeMarker: Function Test

<#ftl strict_syntax="false">

A simple test follows:

${message}

Now perform function tests:

<#assign urls = {"home" : "/home.html", "about" : "/about.html"}> <#assign images = {"home" : "/images/home.png", "about" : "/image/about-us.jpeg"}> <#assign preferences = {"showImages" : true}> <#macro français(url, image, alt)> ${alt} ${var} was here.

Function is defined, now let's call it:

<#t>

Again, but with different parameters:

<@français url=urls.about image=images.about alt="About Us" /> <#if var?exists> Something is wrong here. Good.

A recursive function call:

0)> ${a} <@recurse urls />

Test "catch-all" macro parameter:

<#macro "catch-all" foo bar...> foo=${foo} baz=[<#list bar?keys as key>${key}=${bar[key]}<#if key_has_next>, ] <#assign catchall = .namespace["catch-all"]> <@catchall foo="a"/> <@catchall foo="a" bar="b"/> <@catchall foo="a" bar="b" baz="c"/> <#macro fmt pattern args...> <#list args as arg> <#local pattern = pattern?replace("{" + arg_index + "}", arg)> ${pattern}<#lt>