TWIG的 tests 学习
做逻辑判断的。目前支持的有
divisibleby null even odd sameas constant defined empty
divisibleby
检查是否能被整除
{% if loop.index is divisibleby(3) %}
...
{% endif %}
{% if loop.index is divisibleby(3) %}
...
{% endif %}
null
{{ var is null }}
{{ var is null }}
even
变量是否是偶数{{ var is even }}
{{ var is even }}
odd
变量是否是奇数
{{ var is odd }} <br> <pre name="code" class="html">{{ var is odd }} <p> </p> <p> </p> <p>sameas<br> 检查变量的地址是否相同</p> <p>{% if foo.attribute is sameas(false) %} <br> the foo attribute really is the ``false`` PHP value <br> {% endif %} <br> {% if foo.attribute is sameas(false) %}<br> the foo attribute really is the ``false`` PHP value<br> {% endif %}</p> <p> </p> <p>constant<br> 检查变量的值是否相同</p> <p>{% if post.status is constant('Post::PUBLISHED') %} <br> the status attribute is exactly the same as Post::PUBLISHED <br> {% endif %} <br> {% if post.status is constant('Post::PUBLISHED') %}<br> the status attribute is exactly the same as Post::PUBLISHED<br> {% endif %}</p> <p> </p> <p>defined<br> 测试变量是否定义</p> <p>{# defined works with variable names #} <br> {% if foo is defined %} <br> ... <br> {% endif %} <br> <br> {# and attributes on variables names #} <br> {% if foo.bar is defined %} <br> ... <br> {% endif %} <br> <br> {% if foo['bar'] is defined %} <br> ... <br> {% endif %} <br> {# defined works with variable names #}<br> {% if foo is defined %}<br> ...<br> {% endif %}</p> <p>{# and attributes on variables names #}<br> {% if foo.bar is defined %}<br> ...<br> {% endif %}</p> <p>{% if foo['bar'] is defined %}<br> ...<br> {% endif %}</p> <p> </p> <p>empty<br> 测试变量是否为空,empty的意思是:该变量已经定义,但他的值是 null false 或者是空字符串<br> {# evaluates to true if the foo variable is null, false, or the empty string #} <br> {% if foo is empty %} <br> ... <br> {% endif %} <br> <br> 摘自 jiaochangyun的专栏</p>

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

華為正在全球推出Watch GT 5和Watch GT 5 Pro智慧手錶的軟體版本5.0.0.100(C00M01)。這兩款智慧手錶最近在歐洲推出,標準型號是該公司最便宜的型號。這和諧

《鐵拳》系列總監原田勝宏曾認真嘗試將桑德斯上校帶入這款標誌性格鬥遊戲中。在接受 TheGamer 採訪時,原田透露,他向日本肯德基提出了這個想法,希望將這位快餐傳奇人物納入其中。

特斯拉正在推出最新的全自動駕駛(監督)版本12.5.5,並最終帶來了承諾的Cybertruck FSD 選項,距離皮卡上市十個月後,該功能包含在基礎系列的裝飾價格中。 F

Garmin 將於本月底為其最新的高階智慧手錶提供一組新的穩定更新。回顧一下,該公司發布了系統軟體 11.64,以解決 Enduro 3、Fenix E 和 Fenix 8 的高電池消耗問題(亞馬遜售價 1,099.99 美元)。

2024 年 9 月早些時候,Anker 的 Zolo 140W 充電器被洩露,這是該公司首款帶有顯示器的壁式充電器,這引起了轟動。現在,小李TV在YouTube上發布的新開箱影片讓我們親眼目睹了這款hi

小米即將在中國推出米家石墨烯油汀暖爐。該公司最近在其優品平台上成功舉辦了一次智慧家居產品眾籌活動。根據頁面顯示,該設備已開始出貨至

三星期待已久的「特別版」可折疊手機的推出又迎來了另一個轉折。最近幾週,有關所謂 Galaxy Z Fold 特別版的傳言相當安靜。相反,焦點已轉移到 Galaxy S25 系列,包括

Manjaro 已有十多年的歷史,被認為是最用戶友好的 Linux 發行版之一,適合初學者和高級用戶,易於安裝和使用。這個基於 Arch 的發行版主要在奧地利、德國和法國開發
