Ah, gotcha... So essentially you're treating your code as a function or a macro, and the variables are what you want to pass into it. You may already be aware of this, but FreeMarker includes the ability to create functions and macros:
http://freemarker.sourceforge.net/docs/ref_directive_function.html
http://freemarker.sourceforge.net/docs/ref_directive_macro.html
Functions and macros are very similar to each other, the main difference being that a function in FreeMarker must return a value.
It sounds like you've already got things working for you now, so you might not see much value in converting it to a function or a macro now, but I wanted to throw that out just in case you found it useful!