Skip to content

Commit

Permalink
chore(doc): add example ems_dom_crawler twig filter (#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei authored Oct 18, 2024
1 parent 5d79c2f commit 480c650
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions site-building/twig.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ This filter parses a string and returns a [Symfony DomCrawler](https://symfony.c

Useful to extract content from a html string: `{% set firstP = data.body_fr|ems_dom_crawler.filter('p').first.text %}`

Another example for adding the class `img-fluid` to all img tags:
```twig
{% set crawler = body|emsch_routing|ems_dom_crawler %}
{% for img in crawler.filter('img') %}
{% if img.getAttribute('class') == '' %}
{% do img.setAttribute('class', 'img-fluid') %}
{% endif %}
{% endfor %}
{{ crawler.filter('body').html()|raw }}
```

### Function

#### ems_template_exists
Expand Down

0 comments on commit 480c650

Please sign in to comment.