Drupal - if string contains substring twig

The twig function url() returns a render array, when you render it with the twig filter |render you get a markup object and when you render it again you get a string, which you can check whether it contains a substring:

{% set url = url('<current>') %}
{% if 'test' in url|render|render %}
  <p>url contains "test"</p>
{% endif %}

url() returns an array, as 4x4 says. You can see this if you do a for loop on the variable.

path(), however, seems to return a string that you can do your operation on. But it won't include hostname.

Tags:

Theming

8