Kemal with Jinja templates



examples/kemal/src/jinja.cr
require "kemal"
require "crinja"

get "/" do
  crinja = Crinja.new
  crinja.loader = Crinja::Loader::FileSystemLoader.new("src/views/")

  template = crinja.get_template("home.html.j2")
  template.render({
    "title"   => "With CRinja",
    "planets" => ["Mercury", "Venus", "Earth", "Mars"],
    "cond"    => Random.new.next_bool,
  })
end

Kemal.run

examples/kemal/src/views/home.html.j2
<title>{{ title }}</title>

<h1>{{ title }}</h1>

<ul>
{% for planet in planets %}
  <li>{{ planet }}</li>
{% endfor %}
</ul>

{% if cond %}
Condition is true
{% else %}
condition is false
{% endif %}