5

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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

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.