Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds set block assignments in cn docs #668

Merged
merged 1 commit into from
Feb 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/cn/templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ var env = new nunjucks.Environment(AsyncLoaderFromDatabase, opts);

如果在顶级作用域使用 `set`,将会改变全局的上下文中的值。如果只在某个作用域 (`for`、 `include` 或其他) 中使用,只会影响该作用域。

同样地,你也可以使用区块赋值将一个区块的内容储存在一个变量中。

它的语法和标准的`set`语法相似,只不过你不需要用`=`。区块中从头到`{% endset %}`之间的内容都会被捕获,并作为值来使用。

在某些情境下,你可以用这种语法来替代宏:

```jinja
{% set standardModal %}
{% include 'standardModalData.html' %}
{% endset %}

<div class="js-modal" data-modal="{{standardModal | e}}">
```

### extends

`extends` 用来指定模板继承,被指定的模板为父级模板,查看[模板继承](#模板继承)。
Expand Down