Drupal9 模板TWIG笔记
模板引入模板
{% include '引入的模板路径' %}
判断foo是否是空 #如果foo变量为null,false或空字符串,则计算为true#
{% if foo is empty %} {# ... #} {% endif %}
{% if data.banner_list is not empty %} {% endif %}
{#如果foo变量是数组或可遍历对象,则计算结果为true#}
{% if foo is traversable %} {# ... #} {% endif %}
运算判断 赋值
{% set color_code = (collector.authenticated) ? 'green' : 'red' %}
输出带html数据方法
{{ 带html变量|raw }}
处理URL特殊字符传输问题
{{item.uri|url_encode }}
生成URL
{{path('路由')}}
NODE生成URL方法
{{url('entity.node.canonical', { 'node': 1 })}}