Layouts

On The Route

Create a route

#src/views/pages/user.ecr

get "/user" do
  name = "joe"
  render "src/views/pages/user.ecr", "src/views/layouts/main.ecr"
end

Render Method

Macro Value1 value2 Detail
render src/views/hello.ecr src/views/layouts/main.ecr you pass down the ecr view that you want to render on that route and layout page
view location layout location

On The View

Just put the code you want to show up for that view

#src/views/hello.ecr

<div class="content-area">
  Hey, here goes my html
</div>

Use <%= content %> tag to display the page content on the layout

On The Layout

#src/views/layouts/main.ecr

<html>
<head>
  <title>My Kemal Application</title>
</head>
<body>
  <header>
    <ul class="menu">
      <li><a href="#">Home</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </header>
  <%= content %>
</body>
</html>

results matching ""

    No results matching ""