Is there any function for splitting a string into chunks based on a separator? The opposite of join filter.
I mean something like explode in PHP. I need to check if class parameter contains a given string:
{% macro nav_item(route, label, class, tooltip, placement) %}
{% spaceless %}
{% if 'icon-white' in class|explode(' ') %}
{% edif %}
{% endspaceless %}
{% endmacro %}
Solution for twig prior to 1.10.3
AFAIK, there is no such filter in twig.However you might useinoperator as following:So, for example, if your class looks like
'some-class icon-white icon-white-2'then test_class will take value of' some-class icon-white icon-white-2 'andinwill returntruefor this class. It will, however, returnfalsefor' some-class icon-white-2 ', as expected.