减号 In twig 块定义 [英] Minus In twig block definition

查看:26
本文介绍了减号 In twig 块定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有什么区别:

{%block body %}

还有那个

{%block body -%}

解决方案

刚刚在文档中阅读了一些关于它的内容,不确定这是否也适用于 {% block ... %} 标签.Twig 空白控件

{% set value = '无空格' %}{#- 没有前导/尾随空格-#}{%- 如果是真的 -%}{{- 价值 -}}{%- 万一 -%}{# 输出无空格"#}

还有另一个例子,它修剪了变量前面的空白,但最后没有这样做 - 所以效果只是在一侧.

{% set value = '无空格' %}<li>{{- 值}} </li>{# 输出 '<li>没有空格 </li>'#}

<块引用>

上面的示例显示了默认的空白控件修饰符,以及如何使用它来删除标签周围的空白.修剪空间将消耗标签那一侧的所有空白.可以在标签的一侧使用空白修剪

所以我认为你给定的例子的不同之处在于,在第一个块 body 中,块开始后会有一个空格.在您的第二个示例 body - 中,块开始后没有.只需阅读文档条目即可了解其工作原理.

编辑

一个简单的例子来演示文档中的例子:

{% set value = '源代码中在值"之后/之前没有空格' %}<li>{{- value -}} </li>...

Firebug 中 HTML 标记的输出:

而这个

{% set value = '源代码中value"后的空格' %}<li>{{- 值}} </li>...

输出:

">

注意第二个示例中value"和结束 </li> 之间的空格.因此,减号 - 会在例如之前,之后或两侧擦除/修剪空格一个变量.

What's the difference between this:

{%block body %}

and that

{%block body -%}

解决方案

Just read something about it in the documentation, not sure if this will also apply on {% block ... %} tags. Twig whitespace control

{% set value = 'no spaces' %}
    {#- No leading/trailing whitespace -#}
    {%- if true -%}
        {{- value -}}
    {%- endif -%}
{# output 'no spaces' #}

There's also another example given which trims the whitespace in front of the variable but doesnt't do it at the end - so the effect is only on one side.

{% set value = 'no spaces' %}
    <li>    {{- value }}    </li>
{# outputs '<li>no spaces    </li>' #}

The above sample shows the default whitespace control modifier, and how you can use it to remove whitespace around tags. Trimming space will consume all whitespace for that side of the tag. It is possible to use whitespace trimming on one side of a tag

So I think the difference in your given exmaples is that in the first block body there will be a whitespace after the block started. In your second example body - there's none after the block started. Just read the documentation entry to see how it works.

EDIT

A simple example to demonstrate the example in the docu:

{% set value = 'NO space in source code after/before "value"' %}
<li>    {{- value -}}    </li>
...

outputs in Firebug in the HTML markup:

Whereas this

{% set value = 'space in source code after "value"' %}
<li>    {{- value }}    </li>
...

ouputs:

Notice the space between "value" and the closing </li> in the second example. So the minus - erases/trims a whitespace either before, after or on both sides of e.g. a variable.

这篇关于减号 In twig 块定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆