How to concatenate strings in twig template?

            In my last post we discussed about the “How to hide index.php from url“. Today I will show you how you will concatenate strings in twig template engine. Recently while working with twig template engine found it is more flexible and powerful with beautiful syntax. If you are wondering how you will concatenate string in twig template instead of in your controller (php) file then here are few examples which may help you.

String Concatenate:

{{ 'Hello ' ~ }}

Alternatively you can use join syntax for concatenate strings as below-

   ​ {{ [1, 2, 3]|join }}​​
    {# returns 123 #}


If you would like to have some separator between values using join –

{{ [1, 2, 3]|join('|') }}
{# outputs 1|2|3 #}

Hope you enjoy the post. If you are interested to learn more about twig template engine, just visit official documentation Leave your comments below if you find helpful. Keep visiting for new posts.

Related Posts Plugin for WordPress, Blogger...
Follow Us On Facebook Twitter Google+ Linkedin
Copyright @2011-2013 All rights reserved. Powered By- Sanjoy Dey Productions