Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Templating with Twig Templating Languages Custom Functions

How can a user both name a macro and pass the macro an array argument with a different name?

-Passing a named array is not covered in the 3 videos prior to the quiz. -The symfony documentation on creating a function in twig (what the question is literally asking) differs significantly from creating a macro (what the previous three videos of material cover and what seems to be the obvious expectation of the question )

2 Answers

I am assuming you are talking about this question:

Use the following code to create a custom Twig function named "review", which will displaying the details of a review. The function should accept an array argument named data which has elements matching the ID of each div.

I did some digging and between this and this came up with:

{% macro review(data) %}

Then to access array values use dot notation. For example:

{{ data.rating }}

Thank you Kris, I will give that a shot. I was scored correctly on the quiz for accessing array values w/ dot notation, but was trying all kinds of nonsense trying to get that first question right: {% macro review(data(review, name, content)) %} << thinking that review was the name of the macro and data was the name of the array being passed, and the arguments (review/name/content) matching the values of the div id's being passed in the arguments. Shrug. Color me a code noob.