Search code examples
phptwigsubstringcomparison-operators

Find substring in the string in TWIG


I want to find substring of the string or check if there is no such substring using Twig. On the words, I need analogue of 'strstr' or 'strpos' in php. I googled and searched this issue in stackoverflow but nothing found. Does someone know how to solve this problem?


Solution

  • Just searched for the docs, and found this:

    Containment Operator: The in operator performs containment test. It returns true if the left operand is contained in the right:

    {# returns true #}
    
    {{ 1 in [1, 2, 3] }}
    
    {{ 'cd' in 'abcde' }}