Youngsik Oh
Youngsik Oh

Reputation: 54

How can i use freemarker in jquery?

I'm trying to use freemarker in jquery like this:

someFtlFile.ftl:

<script type="type/javascript" src="./js/someJqueryFile.js">

someJqueryFile.js:

$('#sometextbox').val('${freeMarkerVal}');

I can use ${freeMarketVal} inside "someFtlFile.ftl" with HTML, but i cannot see freeMarkerVal value in textbox.

Is there are something special method to use freemarker in jQuery?

Upvotes: 0

Views: 5053

Answers (3)

acoder2013
acoder2013

Reputation: 390

you should use this one,because the freemarkerContent may contain quotation marks, line-breaks,etc:

var text = "${freemarkerContent?js_string}";

Upvotes: 0

Yannis
Yannis

Reputation: 6157

What you have written above is fine but mind that your freemarker will be evaluated server-side. This means that you cannot manipulate freemarker stuff from javascript. But you can assign javascript variables etc. with freemarker code as long as you realize what that means. The below is fine but if you do View Source in your browser you will see the contents of the freemarkerVal. Hopefully that makes sense.

<script>
var test = '${freeMarkerVal}';
</script>

Upvotes: 1

Mohammad Areeb Siddiqui
Mohammad Areeb Siddiqui

Reputation: 10179

Try this if it works with simple Javascript:

document.getElementById("sometextbox").innerHTML = '${freeMarkerVal}'

Although I know that Freemaker is a Java thing but just gave the solution to stop you using jQuery at very very small things that could be done easily with Javascript.

Upvotes: 0

Related Questions