简体   繁体   中英

How to print values in an array in a twig in symfony 2?

I am passing the following two dimentional array to my twig.

Array (
        [0] => Array ( [restaurantname] => Pizza Hut 
                       [restaurantaddress] => Union Place 
                       [restauranttelephone] => 5555522255 
                       [mstrestaurantstatusid] => 1 
                       [restaurantid] => 1 ) 

        [1] => Array ( [restaurantname] => The Coffee Bean 
                       [restaurantaddress] => Maitland Crescent 
                       [restauranttelephone] => 3333569855
                       [mstrestaurantstatusid] => 1 
                       [restaurantid] => 2 )
      )

Inside my twig, I want to print only the restaurant names. But I'll be using the other information later on. I'm having trouble printing only the restaurant names. Please help. Thank you.

The array in Twig is an associative array. In order to get a relative value, you must specify a key inside square baskets like this:

{{ arrayName['key'] }}

In your case, you just simply pass restaurantname as key of your array:

{{ arrayName['restaurantname'] }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM