Jade Templates with Spring MVC - bahkified/Notes GitHub Wiki

Jade is a templating engine. It is designed primarily for server side templating in node.js, but can be used in many other environments. It is only intended to produce XML like documents (HTML, RSS, etc), so do not use it to create plain text, markdown, CSS, whatever else!

Jade reference

For a reference on Jade syntax, refer to the official website: http://jade-lang.com/

Using Jade for Spring MVC views

Instead of using JSP or HTML view pages, Jade templates can be used. These files will have direct access to the Spring MVC model and any attribute it contains. However, unlike JSPs, it cannot use taglibs. The model must be accessed with javascript.

In order to use Jade views with Spring MVC, the Spring context must be configured correctly. In the config file, _servletName_-servlet.xml, the correct template loader and view resolvers must be set. The following should be enough to get you started using Jade!

    <bean id="templateLoader" class="de.neuland.jade4j.spring.template.SpringTemplateLoader">
        <property name="basePath" value="/WEB-INF/views/"/>
    </bean>

    <bean id="jadeConfiguration" class="de.neuland.jade4j.JadeConfiguration">
        <property name="prettyPrint" value="false"/>
        <property name="caching" value="false"/>
        <property name="templateLoader" ref="templateLoader"/>
    </bean>

    <bean id="viewResolver" class="de.neuland.jade4j.spring.view.JadeViewResolver">
        <property name="configuration" ref="jadeConfiguration"/>
        <property name="renderExceptions" value="true"/>
    </bean>

Of course, these bean definitions have some dependencies that must be included on the classpath. On top of the usual Spring MVC dependencies, the spring-jade4j project must also be included:

    <dependency>
        <groupId>de.neuland-bfi</groupId>
        <artifactId>spring-jade4j</artifactId>
        <version>0.4.0</version>
    </dependency>

Resources

⚠️ **GitHub.com Fallback** ⚠️