symfony - Twig 的 `is not none` 语法
问题描述
当重载 Symfony 的表单模板时,我choice_widget_collapsed
在form_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 empty
is defined
none
解决方案
如Twig Null 文档
中所述,是Twig 语法none
的别名。null
推荐阅读
- postgresql - 在 PostgreSQL 中使用“pg_basebackup.exe”工具进行备份时,有什么方法可以更改备份文件的默认文件名
- python - 检索浏览器中加载的图像
- javascript - fs.readFile 单元测试用例 - “测试完成后无法记录。您是否忘记在测试中等待异步内容?”
- javascript - 拆分后替换Vue中的DOM元素
- python - Python没有名为“请求”的模块,甚至安装请求
- node.js - 基于 botframework v4 node.js 在 bot 中查看 Azure blob 存储中保存的聊天记录
- javascript - 在使用递归模板表示的 n 元树中放置元素时,角度拖放不起作用
- flutter - 标签列表中的一排圆形按钮一起触发
- android-testing - Kakao 测试导航抽屉
- java - Facing issues in multi project build using gradle