Kemal ECR Templates



examples/kemal/src/ecr_template.cr
require "kemal"

get "/" do |env|
  response = ""
  text = env.params.query["text"]?
  if !text.nil?
    response = text
  end
  render "src/views/page.ecr", "src/views/layouts/layout.ecr"
end

Kemal.run

examples/kemal/src/views/page.ecr
<form method="GET" action="/">
<input name="text">
<input type="submit" value="Echo">
</form>
<% if response %>
   You typed in <b><%= response %></b>
<% end %>



examples/kemal/src/views/layouts/layout.ecr
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
  <title><%= title %></title>
</head>
<body>
  <%= content %>
</body>
</html>