首页 > 解决方案 > Twig 的 `is not none` 语法

问题描述

当重载 Symfony 的表单模板时,我choice_widget_collapsedform_div_layout.html.twig.

{%- block choice_widget_collapsed -%}
    {%- if required and placeholder is none and not placeholder_in_choices and not multiple and (attr.size is not defined or attr.size <= 1) -%}
        {% set required = false %}
    {%- endif -%}
    <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
        {%- if placeholder is not none -%}
            <option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (translation_domain is same as(false) ? placeholder : placeholder|trans({}, translation_domain)) }}</option>
        {%- endif -%}
        {%- if preferred_choices|length > 0 -%}
            {% set options = preferred_choices %}
            {{- block('choice_widget_options') -}}
            {%- if choices|length > 0 and separator is not none -%}
                <option disabled="disabled">{{ separator }}</option>
            {%- endif -%}
        {%- endif -%}
        {%- set options = choices -%}
        {{- block('choice_widget_options') -}}
    </select>
{%- endblock choice_widget_collapsed -%}

是什么意思if placeholder is not none?我在 Twig 文档中没有遇到过这样的语法,并且通过谷歌搜索我发现只有从同一个文件中复制的代码,没有任何解释。

我很好奇,为什么不is not null,,?在哪里定义?is not emptyis definednone

标签: symfonytwigsymfony-forms

解决方案


Twig Null 文档 中所述,是Twig 语法none的别名。null


推荐阅读