shard-kemal/docs/views.md

30 lines
502 B
Markdown
Raw Normal View History

# Views
2015-12-07 20:03:35 +00:00
You can use ECR to build views. Kemal serves a `render` macro to use Crystal's built-in `ECR`
library.
2015-12-07 20:03:35 +00:00
## Embedding View File
```crystal
get '/' do |env|
your_name = "Kemal"
render "views/hello.ecr"
end
```
## Writing Views
2015-12-07 20:03:35 +00:00
ECR is pretty similar ERB(from Ruby). As you can see you can easily access the block variables in your view. In this
example `your_name` is available for use in the view.
```
src/
views/
hello.ecr
```
Write `hello.ecr`
```erb
Hello <%= your_name %>
```