wordpress - 我如何在木材/树枝的一行中写多个“if”条件?
问题描述
我有一种情况,我想在一行中编写多个“if”条件,例如:{% if room_status == 'For Rent' and not 'Booked' %}
这显然行不通,但是您可以了解我要完成的工作。
但是不知道如何写这个:
{% if room_status == 'For Rent'%}
{% if room_status != 'Booked' %}
{# <Then run some code here> #}
{% endif %}
{% endif %}
任何建议都非常感谢!
解决方案
来自Twig If文档:
对于多个条件,
and
可以or
使用:
{% if temperature > 18 and temperature < 27 %}
<p>It's a nice day for a walk in the park.</p>
{% endif %}
因此,在您的情况下,这应该有效:
{% if room_status == 'For Rent' and room_status != 'Booked' %}
{# <Then run some code here> #}
{% endif %}
尽管在我看来您并不真的需要第二次检查。room_status
变量只能包含一个值,对吗?它不能同时是“出租”和“已预订”,它要么是一个,要么是另一个。
推荐阅读
- android - 如何在 MotionLayout 过渡期间平滑更改可绘制资源?
- keras - sklearn 的 SVM(铰链)损失函数相对于输入的偏导数是多少?
- android - Gtk中的Android ArrayAdapter等价物?
- python - NameError:未定义名称“encrypted_message_key”
- c# - C# GoogleAPI - 如何在变量类型为“对象”时设置持续时间?
- django - Pipfile.lock (d67565) 过期,更新到 (4f9dd2)
- google-chrome - 我可以自定义 Chromium 错误屏幕吗
- c - 换行符终止输入循环未在 C 中退出
- powerapps - 从选定的组合框中自动填充 2 个组合框值
- reactjs - 在我的标题中,我有令牌,但它说没有令牌,就好像没有令牌一样。但是当它在邮递员上尝试时它工作正常。这里有什么问题