This is the third post in a series on writing cleaner code in your WCMS Velocity formats.
Like templates in XSLT, macros are a useful and idiomatic way to help separate the parts of our Velocity code so that we can better read and re-use them.
There’s an important difference between XSLT templates and Velocity macros, though: while XSLT templates only accept simple scalar values via the
<xsl:with-param> element (unless you want to load up EXSLT), Velocity macros readily accept complex types as parameters, such as nodes or a
Because Velocity macros can accept complex types as parameters, they’re a little more flexible than their XSLT counterparts and in some cases allow us to write fewer formats. However, this power comes at a cost and should be used with care.