Skip to content
Sinatra template support for Thymeleaf.rb
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Gem Version


Sinatra template support for Thymeleaf.rb


Thymeleaf.rb is a Ruby adaptation of Thymeleaf, a natural templating engine.

It allows to create natural templates (HTML that can be correctly displayed in browsers and also work as static prototypes) and render with a data set to provide them functionality.

You can find Thymeleaf.rb here: Templating language is here:


This is a gem so just pop it in your Gemfile:

gem 'sinatra-thymeleaf'

Then, require it and activate the helper in your app:

require 'sinatra/base'
require 'sinatra-thymeleaf'

class App < Sinatra::Base
  helpers Sinatra::Thymeleaf
    get "/test" do
        thyme :test

The views have an html externsion and should be placed in the views directory. That's about it.

I'll continue to add functionality and details, as I'm looking to use this in a project. Please add issues if you spot any problems.

Template parameters

The template variables can be passed by using the locals parameter, like this:

  thyme :test, {:param => 'value'>}

#Localization support You can use i18n localization in your templates, like this:

  <span data-th-text="${t['new.message']}">Some text</span>

This works by using I18n.t directly so remember to configure i18n for your sinatra app

#Flash support You can use the sinatra-flash gem to flash messages through to the thymeleaf template

Just add this to your route:

flash[:success] = "Whohoo!"
flash[:error] = "Damn!"

Also, add this to your template:

<div data-th-unless="${flash[:success].nil?}" class="alert alert-success">
  <span data-th-text="${flash[:success]}"> That worked! </span>
<div data-th-unless="${flash[:error].nil?}" class="alert alert-danger">
  <span data-th-text="${flash[:error]}"> Something went wrong! </span>

And you should be good to go

You can’t perform that action at this time.