cancel
Showing results for 
Search instead for 
Did you mean: 

Processing a freemarker template from Javascript API

randomman
Champ in-the-making
Champ in-the-making
Hi. As part of a content rule I'm executing a script. As part of that script i'd like to run a bit of freemarker to extract part of an xhtml document.

For example:
var strFreemarker = "<#assign dom=document.xmlNodeModel />${dom.html}";   
var strContent = document.processTemplate(strFreemarker);

I'd like to be able to stick in some xpath stuff so I can extract the elements i want. However, my simple test above isn't working. I get the following error:
document.xmlNodeModel is undefined.
Anyone got any pointers on this?

This is an improvement on yesterday when processTemplate failed completely. It turned out that was due to a bug. I'm now running the community 2.2 nightly build to sort that out.
1 REPLY 1

kevinr
Star Contributor
Star Contributor
Well for a start the #assign tag should not be closed with /> - freemarker is not script XML or even close. Is the 'document' object what you think it should be? i.e. are you actually get a useful DOM? The 'document' object for the FreeMarker context will be set to the script node that is executing the processTemplate() call - it is not the document that is the context for the script itself. You will probably need to use the 'args' facility to pass in noderefs etc. of the objects you want to access in Freemarker and look them up.

Hope this helps,

Kevin