Twig Cookbook

Filters

Generate handle from string ( use Wordpress sanitize_title function )

{{ 'My title'|handle }}

--> output : my-title

Handle Wordpress "Read more" tag

{{ post.content|more|raw }}

Resize image

<img src ="{{ post.thumbnail|resize(800,600) }}"/>

Generate picture

{{ post.thumbnail|picture(1280, 680, {'max-width: 420px':[420,665], 'max-width: 768px':[768,820]})|raw }}

--> ouput 

<picture>
    <source media="(max-width: 420px)" srcset="/uploads/image-420x665.webp" type="image/webp"/>
    <source media="(max-width: 420px)" srcset="/uploads/image-420x665.jpg" type="image/jpeg"/>
    <source media="(max-width: 768px)" srcset="/uploads/image-768x820.webp" type="image/webp"/>
    <source media="(max-width: 768px)" srcset="/uploads/image-768x820.jpg" type="image/jpeg"/>
    <source srcset="/uploads/image-1280x680.webp" type="image/webp"/>
    <img src="/uploads/image-1280x680.jpg" alt="" loading="lazy" width="1280" height="680"/>
</picture>

Functions

Execute php functions

Search content for shortcodes and filter shortcodes through their hooks

Get login url

Display search form

Retrieves the permalink for a post type archive

Retrieve the URL for an attachment

Get post permalink by value, available options are : id, state, title

Get term permalink

Display dynamic sidebar

Outputs a complete commenting form for use within a template

Determines whether a sidebar contains widgets

Retrieve the translation of text

Retrieve translated string with gettext context

Translates and retrieves the singular or plural form based on the supplied number

Fire the wp_head action

Fire the wp_footer action.

Instantiate Wordpress bundle post entity

Instantiate bundle user entity

Instantiate bundle term entity

Instantiate bundle image entity

Generate transparent image placeholder

Last updated

Was this helpful?