how to use the php string function in the twig template engine


I want to use few php string functions in twig. For e.g.

How to write below code in twing?

if (!empty($message) && substr_count($message, 'blabla')) {

You can't, and that's the whole point of twig. Template should only take care of displaying data.

In that specific case, you could create a TWIG variable, and simply pass TRUE or FALSE, so that you twig code would look like:

{% if display_message %}
{% enfif %}

You can look at the list of expressions that are available in the twig template, strstr_count is not part of them :(