Skip to main content

Functions

Functions are called directly in expressions, unlike filters which transform a value with the pipe | operator.

{{ min(1, 2, 3) }}
{{ get_post(42).title }}
{{ html_classes('btn', {active: is_active}) }}

Utility

FunctionExampleDescription
minmin(1, 2, 3)Smallest value
maxmax(prices)Largest value
randomrandom(['red', 'green', 'blue'])Random value
rangerange(1, 10)Generate a sequence
cyclecycle(['odd', 'even'], loop.index)Cycle through values
datedate()|date('Y-m-d')Create a timestamp
html_classeshtml_classes('btn', {active: true})Conditional CSS classes

WordPress

FunctionExampleDescription
get_postget_post(42).titleSingle post by ID
get_postsget_posts({post_type: 'page'})Posts by query args
get_termget_term(5).nameSingle term by ID
get_termsget_terms({taxonomy: 'category'})Terms by query args
get_userget_user(1).display_nameSingle user by ID
get_usersget_users({role: 'author'})Users by query args
get_imageget_image(100).src('medium')Single image by ID