Common Macros for templates in plugins

18 views
Skip to first unread message

Ben Wagner

unread,
Apr 10, 2026, 3:50:58 PMApr 10
to xnat_discussion
Hi XNAT gurus.
  I'm trying to see if there is a better way to do this.  I have common macros I use across several plugins.  Rather than potentially clobber things with each having their own I have them in their own plugin.  For the longest I've been modifying WEB-INF/conf/xnat17.properties with the items below and re-rolling my war file.  I'd really like to stop doing that.  Is there a better way to get new macro libraries into the system since the old 1.7 days?  And MathTool/DateTool.

Thanks,
Ben

# -------------------------------------------------------------------
#
#  V E L O C I T Y  S E R V I C E
#
# -------------------------------------------------------------------


# Load our VelociMacros
services.VelocityService.velocimacro.library = macros/xnat17Macros.vm,macros/ansirMacros.vm,macros/xtkMacros.vm

# -------------------------------------------------------------------
#
#  I N T A K E   S E R V I C E
#
# -------------------------------------------------------------------

# The location of the xml file specifying valid inputs
#
# If you need to define multiple definition files, you can should
# seperate them with commas.
#
services.IntakeService.xml.path = WEB-INF/conf/xnat17-intake.xml

########################################################################
#
# Add your application specific extensions here.
#
########################################################################
tool.global.mathTool = org.apache.velocity.tools.generic.MathTool
tool.global.dateTool = org.apache.velocity.tools.generic.DateTool

Ben Wagner

unread,
Apr 21, 2026, 12:25:41 PMApr 21
to xnat_di...@googlegroups.com
An OK solution. Added this to the build gradle.

  def siteCustomizationMacroDir = file("../SiteCustomizationAllPlugin/src/main/resources/META-INF/resources/templates/macros")

  tasks.named("processResources") {
      // Package shared velocity macros into this plugin's web-resource template path.
      if (siteCustomizationMacroDir.exists()) {
          from(siteCustomizationMacroDir) {
              include "ansirMacros.vm", "xtkMacros.vm"
              into "META-INF/resources/templates/macros"
          }
      } else {
          logger.warn("SiteCustomization macro directory not found: " + siteCustomizationMacroDir)
      }
  }

Then parse the macro files instead at the top of each template needing them.  Not as clean as before but lets me keep one master location for the templates.  Still a bit of changes for clobbering, but I think it will be an acceptable trade off.

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/xnat_discussion/8e23b442-2b53-4cd6-9f18-ce4b86364de1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages