Find the first occurrence of a string and return the rest of the string including the search string.

strstr

{{$haystack|strstr:<needle>}}

Arguments

ArgumentDescription
1The string to search for.
2

By default everything after the string (including the needle is returned. If this option is set to true, this method will return the part of the haystack before the first occurrence of the needle (excluding the needle). 

Examples

strstr

{{$text = 'name@example.com'}}

{{$text|strstr:"@"}}
{{$text|strstr:"@":true}}

Output:
@example.com
name

If-statement

{{$text = 'This is a book'}}

{{if $text|strstr:"book"}}
   Yes, the haystack contains the word book.
{{else}}
   No, the haystack doesn't contain the word book.
{{/if}}

Output:
Yes, the haystack contains the word book.