# Twig Cookbook

#### Filters

Generate handle from string ( use Wordpress sanitize\_title function )

```liquid
{{ 'My title'|handle }}

--> output : my-title
```

Handle Wordpress "Read more" tag

```liquid
{{ post.content|more|raw }}
```

Resize image

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

Generate picture

```twig
{{ 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

```liquid
{{ fn('sanitize_title', 'My title') }} 
{{ function('sanitize_title', 'My title') }}
```

Search content for shortcodes and filter [shortcodes](https://developer.wordpress.org/reference/functions/do_shortcode/) through their hooks

```liquid
{{ shortcode(post.content) }}
```

Get [login url](https://developer.wordpress.org/reference/functions/wp_login_url/)

```liquid
{{ login_url() }}
```

Display [search form](https://developer.wordpress.org/reference/functions/get_search_form/)

```liquid
{{ search_form() }}
```

Retrieves the permalink for a [post type archive](https://developer.wordpress.org/reference/functions/get_post_type_archive_link/)

```liquid
{{ archive_url('guide') }}
```

Retrieve the URL for an [attachment](https://developer.wordpress.org/reference/functions/wp_get_attachment_url/)

```liquid
{{ attachment_url(10) }}
```

Get post permalink by value, available options are : id, [state](https://metabolism.gitbook.io/symfony-wordpress-bundle/guides/wp-steroids-plugin/page-states), [title](https://developer.wordpress.org/reference/functions/get_page_by_title/)

```liquid
{# post_url(value, type) #}
{{ post_url('My post', 'title') }}
```

Get [term permalink](https://developer.wordpress.org/reference/functions/get_term_link/)

```liquid
{{ term_url(10, 'item') }}
```

Display [dynamic sidebar](https://developer.wordpress.org/reference/functions/dynamic_sidebar/)

```liquid
{{ dynamic_sidebar(1) }}
```

Outputs a complete [commenting form](https://developer.wordpress.org/reference/functions/comment_form/) for use within a template

```liquid
{{ comment_form() }}
```

Determines whether a [sidebar contains widgets](https://developer.wordpress.org/reference/functions/is_active_sidebar/)

```liquid
{{ is_active_sidebar(1) }}
```

Retrieve the [translation](https://developer.wordpress.org/reference/functions/translate/) of text

```liquid
{{ _e('Submit') }}
{{ __('Submit') }}
```

Retrieve [translated string](https://developer.wordpress.org/reference/functions/_x/) with gettext context

```liquid
{{ _x() }}
```

Translates and retrieves the [singular or plural ](https://developer.wordpress.org/reference/functions/_n/)form based on the supplied number

```liquid
{{ _n() }}
```

Fire the wp\_head action

```liquid
{{ wp_head() }}
```

Fire the wp\_footer action.

```liquid
{{ wp_footer() }}
```

Instantiate Wordpress bundle post entity

```liquid
{% set post = Post(10) %}
```

Instantiate bundle user entity

```liquid
{% set user = User(10) %}
```

&#x20;Instantiate bundle term entity

```liquid
{% set term = Term(10) %}
```

Instantiate bundle image entity

```liquid
{% set image = Image(10) %}
```

Generate transparent image placeholder

```liquid
<img src="{{ pixel(10,20) }}"/>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://metabolism.gitbook.io/symfony-wordpress-bundle/guides/twig-cookbook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
