Contact Form

Name

Email *

Message *

Cari Blog Ini

Twig Replace

Twig replace filter

Summary

The replace filter replaces placeholders in a string. The placeholder format is free-form.

Details

The replace filter formats a given string by replacing the placeholders. Placeholders are free-form.

For example, you have a template twig in html:

```html {% set name = 'Fabien' %}

Hello {{ name }}!

```

In Twig, you have to enclose expressions in parentheses to use them as keys. For example:

```html {% set name = 'Fabien' %}

Hello {{ (name) }}!

```

If you use Twig inside Symfony, use the kernelresponse event to get the response and apply a simple str_replace or preg_replace function.


Comments