If I understand correctly, some templating transforms the <var>s, etc., into JavaScript. Why not write the JS as a regular program? The syntax you have doesn't seem dramatically easier than just ordinary JS and has to be a bit confining.
Is it really that repetitive, or does the code need to be expanded in different ways in different contexts?
Is it really that repetitive, or does the code need to be expanded in different ways in different contexts?