Share Buttons with Spring, Velocity and Thymeleaf

If you visit NixMash Spring Posts you’ll find new Share Buttons. Each of the posts in the stream has their own share buttons, which are also displayed on the post permalink page.


For the share buttons displayed in the post stream shown above we add the HTML to our Velocity Post Footer template shared by all post types.

Velocity populates our links with model properties we pass to the template from our Model. The applicationSettings is our Spring Bean containing our external properties. We could pass our applicationSettings component to the template, but using shareSiteName and shareUrl simplies our template HTML.


We use Thymeleaf to display the share buttons on the Post Permalink page. You can see how similar the HTML is to our Velocity Template above.

And just as we passed properties from our Velocity Model we will pass Model Attributes from our Spring MVC Controller to Thymeleaf.

We like uniformity across frameworks!

Source Code Notes for this Post

All source code discussed in this post can be found in my NixMash Spring GitHub repo and viewed online here.