I’m new to Spring (not to Java) and I just can’t wrap my head around all the tiles stuff. What I want to do is to have a layout with a placeholder for JavaScript includes.
In .Net I can define a master page which contains some content placeholders.
Layout.Master
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<asp:ContentPlaceHolder ID="javascripts" runat="server" />
</head>
<body>
<asp:ContentPlaceHolder ID="content" runat="server" />
</body>
</html>
In the view for the action I can then define how the placeholder should be replaced.
index.aspx
<asp:Content ID="Content" ContentPlaceHolderID="content" runat="server">
This is the body content
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="javascripts" runat="server">
<script src="foo.js" type="text/javascript" charset="utf-8"></script>
</asp:Content>
How can I do that in Spring? I have seen that VelocityLayoutView has a similar functionality but I couldn’t figure out how to define content for placeholders from within a tile.
What you’re looking for is a templating engine with support for template inheritance and defining arbitrary placeholders.
I don’t know of many that do (in java world there’s a bias towards template composition and that’s what plain jsp:include, tiles etc do).
StringTemplate supports inheritance and there is a plugin for spring that adds support for ST, but I don’t know if the plugin supports template inheritance and ST inheritance AFAIK doesn’t let you define placeholders.
Another option is Jangod
Looks like it does what you’re looking for.
For example (taken from their website):
Base template
Template, which extends base template:
It has support for Spring MVC.