Cygnite PHP Framework

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 ' ~ user.name }}

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

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

Or

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.

Follow Us On Facebook Open Source Web Developers by Appsntech facebook group Twitter Open Source Web Developers by Appsntech twitter group Google+ Open Source Web Developers by Appsntech Google group Linkedin Open Source Web Developers by Appsntech, LinkedIn group
Copyright @2011-2013 www.appsntech.com. All rights reserved. Powered By- Sanjoy Dey Productions