ビュー内のブロック

□未翻訳

□翻訳中

■翻訳完了(細田謙二)

■レビュー(Omi Chiba)

ビュー内のブロック

ビューをよりモジュール化するためのもう1つの方法は{{block...}}を用いることです。この仕組は、上記の節で説明した仕組みの代替案になります。

Another way to make a view more modular is by using {{block...}}s and this mechanism is an alternative to the mechanism discussed in the previous section.

次の"layout.html"を考えます:

Consider this "layout.html":

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

<html>

<body>

{{include}} <!-- must come before the two blocks below -->

<div class="sidebar">

{{block mysidebar}}

my default sidebar

{{end}}

</div>

</body>

</html>

そして、次の拡張ビューも考えます。

and this extending view

1.

2.

3.

4.

5.

{{extend 'layout.html'}}

Hello World!!!

{{block mysidebar}}

my new sidebar!!!

{{end}}

これは次のような出力を生成します:

It generates the following output:

1.

2.

3.

4.

5.

6.

7.

8.

<html>

<body>

Hello World!!!

<div class="sidebar">

my new sidebar!!!

</div>

</body>

</html>

ブロックは複数定義することができます。拡張元のビューに置いてブロックが提示されているが、拡張先のビューではされていない場合、拡張元のビューの内容が使用されます。

You can have many blocks and if a block is present in the extended view but not in the extending view, the content of the extended view is used.