Search code examples
javascripttemplatesalfrescofreemarker

List javascript array in alfresco freemarkuer template


Basically I the have following JavaScript arrays filled:

array1 = new Array(1, 2, 3);
array2 = new Array("Title1", "Title2", "Title3");
array3 = new Array("10-02-2017", "11-02-2017", "12-02-2017");

bigArray = new Array();
bigArray.push(array1);
bigArray.push(array2);
bigArray.push(array3);

model.entry = bigArray;

Now in the ftl file I would like to get the following output out of the ftl File:

1, Title1, 10-02-2017
2, Title2, 11-02-2017
3, Title3, 12-02-2017

How do I "call" such a usecase? Ich haven't even an idea what to google for, so i could read manuals and stuff. Can you help or recommend some useful tutorial?


Solution

  • I just solved it by splitting my bigArray into the single Arrays.

    So I have no longer:

    bigArray = new Array();
    bigArray.push(array1);
    bigArray.push(array2);
    bigArray.push(array3);
    
    model.entry = bigArray;
    

    Now I have:

    model.ids = array1;
    model.titles = array2;
    model.dates = array3;
    

    And then I output them like this:

    IDs:
    <#list ids as id>
      ${id}<#sep>,
    </#list><br>
    
    Titles:
    <#list titles as title>
      ${title}<#sep>,
    </#list><br>
    
    Dates:
    <#list dates as date>
      ${date}<#sep>,
    </#list><br>
    

    So my output looks a bit different:

    IDs: 1,2,3
    Titles: Title1, Title2, Title3
    Dates: 10-02-2017, 11-02-2017, 12-02-2017
    

    Thanks for you help!