2015-12-06 14:05:16 +00:00
|
|
|
# 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`
|
2015-12-06 14:05:16 +00:00
|
|
|
library.
|
|
|
|
|
2015-12-07 20:03:35 +00:00
|
|
|
## Embedding View File
|
|
|
|
|
|
|
|
```crystal
|
|
|
|
get '/' do |env|
|
|
|
|
your_name = "Kemal"
|
|
|
|
render "views/hello.ecr"
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2015-12-06 14:05:16 +00:00
|
|
|
## 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.
|
2015-12-06 14:05:16 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
src/
|
|
|
|
views/
|
|
|
|
hello.ecr
|
|
|
|
```
|
|
|
|
|
|
|
|
Write `hello.ecr`
|
|
|
|
```erb
|
|
|
|
Hello <%= your_name %>
|
|
|
|
```
|