Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create "object" in freemarker only (no JAVA etc)?

After reading Freemarker documentation and googling about it I just don't see how can I build my test object (like associated, multilevel array) in freemarker only.

So like:

<#assign seq=["a","b","c"]>

But in more depth - like (pseudo):

   a
     aa ab ac ad
   b
     ba bb bc
   c
     ca cb cc cd ce

Is this possible in freemarker only (as front-end dev waiting for back-end guys to finish it I would really need something like this to work on and not use bare arrays)?

Tnx

like image 847
nettutvikler Avatar asked Mar 19 '23 10:03

nettutvikler


1 Answers

That's not just a multi-level array, because each nested array has a name ("a", "b", "c"). The closest I can think of is:

<#assign foo = {
    "a": ["aa", "ab", "ac", "ad"],
    "b": ["ba", "bb", "bc"],
    "c": ["ca", "cb", "cc", "cd", "ce"]
}>

But there you have utilized that FTL hash literals keep their key order. Without that:

<#assign foo = [
    {"name" : "a", "value": [ "aa", "ab", "ac", "ad"]},
    {"name" : "b", "value": [ "ba", "bb", "bc"]},
    {"name" : "c", "value": [ "ca", "cb", "cc", "cd", "ce"]}
]>
like image 116
ddekany Avatar answered Mar 20 '23 23:03

ddekany