php - How to add a delimiter in twig to a string? -
php - How to add a delimiter in twig to a string? -
i have time in format hhmm string , add together " : " after hours. there simple filter split string after 2 characters , add together delimiter?
you can split position this
{% set bar = "aabbcc"|split('', 2) %} {# bar contains ['aa', 'bb', 'cc'] #} as described in doc
so can like:
{% set bar = "1203"|split('', 2) %} {# bar contains ['12', '03'] #} now let's do:
{{ bar[0]~":"~bar[1] }} this output:
12:03 better if build macro or twig extension function
hope help
php symfony2 twig
Comments
Post a Comment