if
If is the conditional block
{% if user.admin %} Admin user! {% else %} Not admin user {% endif %} There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
Some examples on how to work with different kind of conditions:
{% if user.email == empty %} Please enter your e-mail address {% endif %} {% if user.name == 'peter' and user.name != 'John' %} Hello you, Non-John Peter! {% endif %} {% if ball.count < 1 %} You have no balls {% endif %} # Check if array contains desired value, e.g. ['foo', 'bar'] {% if array contains 'foo' %} There is a 50/50 chance that this array also contains "bar" :) {% endif %} # Check if string contains desired value, e.g 'hello world' {% if some_string contains 'hello' %} String contains "hello" {% endif %}
- Basics
- Variables
- Filters
- Components
- Localization
- Keyboard shortcuts
- Objects
- Article
- Asset
- Blog
- Comment
- Element
- Language
- Mediaset
- Menu item
- Page
- Person
- Site
- Tag
- Data
- Tags
- addbutton
- assign
- blogcontext
- case
- capture
- commentform
- content
- contentblock
- cycle
- editable
- elementscontext
- for
- grouped
- if
- ifchanged
- image
- include
- load
- login
- loginblock
- menuadd
- menubtn
- menulink
- reorder
- rss_link
- stylesheet_link
- unless
- xcontent
- Examples
- Creating a navigation menu
- Creating language selection
- Blog page example
- Blog article example
- Complete page example
- Breadcrumbs
- Standard theme definition
- Elements listing
- Element page
- Components