1

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.

4
  • We assume you are asking a question after days of research. Thus, show us what you've tried. Commented Nov 19, 2013 at 14:12
  • Yes I did some research, but failed to achieve what I actually want. Commented Nov 19, 2013 at 14:16
  • @WouterJ why is this down-voted? I just asked a legitimate question. And I am new to symfony2. Commented Nov 19, 2013 at 14:29
  • because you're question does not follow our "guidelines" for a good question. You are only asking a question, without showing what you've tried. Read How to Ask for more information. Commented Nov 19, 2013 at 16:19

1 Answer 1

7

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'] }}

Sign up to request clarification or add additional context in comments.

1 Comment

{{ arrayName.restaurantname}} works like this too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.