Managing shared Velocity template markup/code

Hello,

We would like to build and maintain several XML publishing templates for our growing list of content types and have common sets of elements and logic I would like to include in more than one template. I would like to extract out this logic into its own template and source that from the calling templates. Is this possible in Rhythmyx?

I am aware of rx_assembly.vm and we have added many macros there, but with a growing codebase and a team of developers, it is becoming more and more difficult (and dangerous) to continue to add to this one file.

I am thinking Velocity’s #parse directive would work well in this regard to be able to include a particular vm file from a Rhythmyx template, but I am not sure how or if this would be supported within Rhythmyx and the Workbench. A base requirement here would be to have access to all the parameters made available to the calling template, such as $sys.item.

Has anyone tackled this already? Or can you comment on whether something like this would work? At a minimum, it would be helpful to be able to at least break out code currently in rx_assembly.vm into various smaller files and call them all from the main one. Anything to promote more modularity here.

Thanks,
Steve

I can think of two options:

a) Write custom JEXL expressions (see http://forum.percussion.com/showthread.php?t=2051)

b) Create multiple .vm files in /Rhythmyx/rx_resources/vm. You would need to “declare” these new files to the velocityAssembler (WB > System Design > Extensions > Assemblers > velocityAssembler, click "Additonal Parameters).

Then you need to do a reinitialization. There are two ways to do so:
i) restart cms
ii) preview any template but attached to the URL a “reinit” parameter, which I forgot exactly what it is, either “reinit=true” or “sys_init=true” or something similar…

You would want to test your custom macros thoroughly first. If there is an error, then none of your other velocity templates, using the custom macros or not, will work properly, and you will have to do a cms restart to set things right.

Thanks Jason!

I tried adding a new macro file on the file system, option (b), and that worked.

Is there a way to tie this into the Workbench so that my new .vm files show up alongside “User Velocity Macros” under System Design > Configurations? Right now, my new file is not visible from within Workbench and requires going out to the file system to edit it directly.

It would also be nice if the editor would present the macros in my new file when suggesting macros to choose from while typing the macro name in the calling template.

Stephen,

It would also be nice if the editor would present the macros in my new file when suggesting macros to choose from while typing the macro name in the calling template.

See “Adding Macros to the Snippet Drawer” in the Rhythmyx Technical Reference Manual.

RLJII