Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.