Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call JavaScript function from Freemarker?

I have some basic JavaScript function:

<script type="text/javascript">
    function someTestFunction(param1, param2) {
        //do something
    }
</script>

and Freemarker code:

<#if something==somethingElse>
    // call: someTestFunction(something, 123)
<#else>
    // call: someTestFunction(somethingElse, 345)
</#if>

my question is: Is it possible, and if so, how to call someTestFunction() from inside freemarker tags?

like image 952
SP5RFD Avatar asked Jul 04 '12 11:07

SP5RFD


People also ask

How to call javascript function in FreeMarker?

Freemarker is a java templating language, meaning it is executed on the server. javascript is executed on the client (user's browser). You cannot call a javascript function from the java server in this manner. which means the javascript wll be executed on the client side depending on what server variable is set.

How do you comment on FreeMarker?

Comments: Comments are similar to HTML comments, but they are delimited by <#-- and --> . Comments will be ignored by FreeMarker, and will not be written to the output.


1 Answers

Freemarker is a java templating language, meaning it is executed on the server. javascript is executed on the client (user's browser). You cannot call a javascript function from the java server in this manner.

You could do something like:

<script>
<#if something==somethingElse>
    someTestFunction(something, 123);
<#else>
     someTestFunction(somethingElse, 345);
</#if>
</script>

which means the javascript wll be executed on the client side depending on what server variable is set.

like image 78
Andy Ray Avatar answered Nov 14 '22 22:11

Andy Ray