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 shortcodesarrow-up-right through their hooks

Get login urlarrow-up-right

Display search formarrow-up-right

Retrieves the permalink for a post type archivearrow-up-right

Retrieve the URL for an attachmentarrow-up-right

Get post permalink by value, available options are : id, state, titlearrow-up-right

Get term permalinkarrow-up-right

Display dynamic sidebararrow-up-right

Outputs a complete commenting formarrow-up-right for use within a template

Determines whether a sidebar contains widgetsarrow-up-right

Retrieve the translationarrow-up-right of text

Retrieve translated stringarrow-up-right with gettext context

Translates and retrieves the singular or plural arrow-up-rightform 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