Twig 的 tags学习(中文) 之三 完结(2)
{% use "blocks.html" with sidebar as parent_sidebar %}
{% block sidebar %}
{{ block('parent_sidebar') }}
{% endblock %}
{% extends "base.html" %}
{% use "blocks.html" with sidebar as parent_sidebar %}
{% block sidebar %}
{{ block('parent_sidebar') }}
{% endblock %}
你可以使用任意数量的use标签,如果多个use标签里的block名字存在重复,那么最后use的那个有效。
spacelsee标签
会删除html标签之间的空白
{% spaceless %}
<div>
<strong>foo</strong>
</div>
{% endspaceless %}
{# output will be <div><strong>foo</strong></div> #}
{% spaceless %}
<div>
<strong>foo</strong>
</div>
{% endspaceless %}
{# output will be <div><strong>foo</strong></div> #}
autoescape标签
这个十分汗颜,我居然没看懂。我只知道字面上的意思是自动转义。。但是。。我做实验的时候 还是不知道应怎么使用
他官方给的例子是
{% autoescape true %}
Everything will be automatically escaped in this block
{% endautoescape %}
{% autoescape false %}
Everything will be outputed as is in this block
{% endautoescape %}
{% autoescape true js %}
Everything will be automatically escaped in this block
using the js escaping strategy
{% endautoescape %}
{% autoescape true %}
Everything will be automatically escaped in this block
{% endautoescape %}
{% autoescape false %}
Everything will be outputed as is in this block
{% endautoescape %}
{% autoescape true js %}
Everything will be automatically escaped in this block
using the js escaping strategy
{% endautoescape %}
而我这么测试。输出的还是原本的内容。
{% autoescape true %}
<body><b>aaaa</b></body>
{% endautoescape %}
{% autoescape false %}
<b>aaaa</b>
{% endautoescape %}
{% autoescape true js %}
<script>
function aaa(){alert('x');}
</script>
{% endautoescape %}
{% autoescape true %}
<body><b>aaaa</b></body>
{% endautoescape %}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>