Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Velocity (Storefront)

Velocity (Storefront)

Velocity is a templating engine. It is used to merge data from the application with HTML templates to generate the HTML that is displayed to user in the storefront. The velocity.xml file is located in the ep-storefront\src\main\resources\spring\views\velocity directory. It contains settings that allow you to configure the Velocity engine.

Warning:

Changes made to the Commerce Manager velocity.xml must be applied to the Velocity (Storefront). If they don't match, unexpected errors could occur.

The cacheSeconds property of the globalMessageSource bean specifies how long message source resource files are cached. In production, it should be set to -1 (infinite). For testing purposes, it can be set to a positive value. This will allows you to test changes to message source resource files without having to restart your application or servlet container.

            storefront/ep-storefront/src/main/resources/spring/views/velocity/velocity.xml
	<!-- message source to be used by velocity templates. -->
    <bean id="messageSource" class="com.elasticpath.commons.util.impl.StoreThemeMessageSource" >
		<property name="storeConfig" ref="threadLocalStorage"/>
		<property name="storeMessageSource" ref="storeMessageSourceDelegate"/>
		<!-- True if you want missing messages to show up as just the key used to look for them. e.g. user.firstname.
			 False will allow exception to be thrown, and stop template render. -->
       <property name="useCodeAsDefaultMessage">
            <value>true</value>
        </property>
    </bean>
	<bean id="storeMessageSourceDelegate" class="com.elasticpath.commons.util.impl.StoreMessageSourceImpl">
		<property name="messageSourceCache">
            <ref bean="messageSourceCache"/>
        </property>
		<property name="globalMessageSource">
            <ref bean="globalMessageSource"/>
        </property>
        <property name="settingsReader" ref="settingsReader"/>
	</bean>


	<bean id="globalMessageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
	    <property name="basenames">
	        <list>
	            <value>org.springframework.security/messages</value>
	        </list>
	    </property>
        <!-- Set cacheSeconds to -1 in Production Environment -->
	    <property name="cacheSeconds"><value>${ep.velocity.cache.seconds}</value></property>
	    <property name="defaultEncoding"><value>UTF-8</value></property>
	</bean>

         

For optimal performance, the following properties on the velocityProperties bean definition should also be set:

  • file.resource.loader.cache: Set this value to true for production to cache templates in Velocity's loader. Set this value to false for development so that changes to templates will take effect immediately.
  • velocimacro.library.autoreload: This parameter enables/disables automatic reloading of Velocity macros. Set this value to false for production. For development, setting this value to true will allow changes to Velocity macros to take effect without restarting the server. This requires file.resource.loader.cache to be set to false.
  • velocimacro.messages.on: Set this value to false for production for improved performance. When developing Velocity templates, this value can be set to true to see Velocity logging and debugging information.
  • runtime.log.logsystem.class: Set this value to org.apache.velocity.runtime.log.NullLogSystemas shown below for production.
    <entry key="runtime.log.logsystem.class"><value>org.apache.velocity.runtime.log.NullLogSystem</value></entry>