I’ve come across a case where a client wants to have a component that is only slightly different on each page. So instead of making a seperate content item for each variation, I’ve built a module that’s reusable and context-aware.
Here’s how:
Velocity Engine 1.6 and higher (1.6.2 ships with CM System version 6.7) has a directive called #evaluate(). This allows you to execute template code loaded from a source other than the template itself.
In my case, I created a Widget content type. The idea being that CMS Admins could create a template fragment as a Widget content item and allow that fragment to be slotted into other content items. In order to truly make this work, I needed to redefine the #slot() #initslot() and #__slotsetup() macros to use the cloneParentItem instead of the sys.item.
If anyone is interested in learning more about this solution, let me know.