Discussion:
[FreeMarker-user] how to set a variable inside a page that uses a macro?
S Ahmed
2012-06-30 17:32:13 UTC
Permalink
So I decided doing this in my macro with regards to injecting javascript
from a page that uses the macro master.ftl:

<#macro master javascript="" >

<#nested>

<script>
$(javascript}
</script>

</#macro>

Now my page looks like:

<#import "/layout/master.ftl" as p>
<@p.master>


</@p.master>

Now how can I create a javascript varialbe to pass to the master from
within this page? Say I have this:

<#import "/layout/master.ftl" as p>
<@p.master>

function sayHello() {
alert("hello world " + "${user.name}");
};


</@p.master>

How can I create a javascript variable and assign it to the javascript
function I created?
Daniel Dekany
2012-06-30 21:14:51 UTC
Permalink
Post by S Ahmed
So I decided doing this in my macro with regards to injecting
<#macro master javascript="" >
<#nested>
<script>
$(javascript}
</script>
</#macro>
<#import "/layout/master.ftl" as p>
Now how can I create a javascript varialbe to pass to the master
<#import "/layout/master.ftl" as p>
function sayHello() {
alert("hello world " + "${user.name}");
};
How can I create a javascript variable and assign it to the javascript function I created?
I assume you want to specify something else between the @p.master
tags. Then:

<#import "/layout/master.ftl" as p>
<#assign js>
function sayHello() {
alert("hello world " + "${user.name}");
};
</#assign>
<@p.master js>
...
</@p.master>
--
Best regards,
Daniel Dekany
Continue reading on narkive:
Loading...