Add README section on new way of nesting layouts

Add README section "Templates with `yield` and nested layouts" in English and Russian.
This commit is contained in:
Alexey Muranov 2013-02-25 15:42:52 +01:00
parent f47ddf8120
commit 2e8d3e6dd0
2 changed files with 76 additions and 0 deletions

View File

@ -898,6 +898,43 @@ Or, specify an explicit Hash of local variables:
This is typically used when rendering templates as partials from within
other templates.
### Templates with `yield` and nested layouts
A layout is usually just a template that calls `yield`.
Such a template can by used either through the `:template` option as
described above, or it can be rendered with a block as follows:
```ruby
erb :post, :layout => false do
erb :index
end
```
This code is mostly equivalent to `erb :index, :layout => :post`.
Passing blocks to rendering methods is most useful for creating nested
layouts:
```ruby
erb :main_layout, :layout => false do
erb :admin_layout do
erb :user
end
end
```
This can also be done in fewer lines of code with:
```ruby
erb :admin_layout, :layout => :main_layout do
erb :user
end
```
Currently the following rendering method accept a block: `erb`, `haml`,
`liquid`, `slim `, `wlang`.
Also the general `render` method accepts a block.
### Inline Templates
Templates may be defined at the end of the source file:

View File

@ -920,6 +920,45 @@ end
Это обычный подход, когда шаблоны рендерятся как части других шаблонов.
### Шаблоны с `yield` и вложенные раскладки (layout)
Раскладка (layout) обычно представляет собой шаблон, который исполняет
`yield`.
Такой шаблон может быть либо использован с помощью опции `:template`,
как описано выше, либо он может быть дополнен блоком:
```ruby
erb :post, :layout => false do
erb :index
end
```
Эти инструкции в основном эквивалентны `erb :index, :layout => :post`.
Передача блоков интерпретирующим шаблоны методам наиболее полезна для
создания вложенных раскладок:
```ruby
erb :main_layout, :layout => false do
erb :admin_layout do
erb :user
end
end
```
Это же самое может быть сделано короче:
```ruby
erb :admin_layout, :layout => :main_layout do
erb :user
end
```
В настоящее время, следующие интерпретирубщие шаблоны методы
принимают блок:
`erb`, `haml`, `liquid`, `slim `, `wlang`.
Общий метод заполнения шаблонов `render` также принимает блок.
### Включённые шаблоны
Шаблоны также могут быть определены в конце исходного файла: