16

Is it possible to assign a freemarker list to a Javascript Array? Does any other technique exist to achieve the same?

Suppose I have the following code

<#list messages.thread.messages.topic as message>
<div id="subject">${posts.subject}</div>
<div id="teaser">${posts.teaser}</div>
<div id="body">${message.body}</div>
</#list>

function script(){
   //I want to access the free marker list message here
}
5
  • You'll need to show what's the generated HTML. Also, are you using any library or just plain JavaScript? Commented Dec 27, 2011 at 9:21
  • What is a "free marker list"? Commented Dec 27, 2011 at 9:21
  • @jfriend00 - He's talking about FreeMarker - freemarker.sourceforge.net Commented Dec 27, 2011 at 9:26
  • I don't find anything wrong in my question and yet it is voted negative. Check below for the answer I found out. Commented Dec 28, 2011 at 5:09
  • 1
    +1 to offset pointless downvote. Commented Sep 18, 2012 at 16:49

2 Answers 2

20

Yes it is possible

var arr=[<#list messages.thread.messages.topic as message>${message.body},</#list>]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! For me, the following worked as it was a long data type. var arr = [<#list dataIds as dId>${dId?c},</#list>];
1

Yes it is possible. You need to arrange that your Freemarker template generates a Javascript array literal and assigns it to the appropriate Javascript variable. Start with the syntax of a Javascript array literal and then figure out how to generate one using Freemarker constructs.

3 Comments

Thanks Stephen. I found how to.
I don't find anything wrong in my question and yet it is voted negative.
@rozar - yea. Stuff like that happens. People assume that since they don't understand the question that it must be a poor question. Don't worry about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.