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

Henrik Killi
Henrik Killi
7,902 Points

I cannot figure out how to finish the code snippets in this quiz...

I have tried a number of different ways to write the code. I have also read the https://twig.symfony.com/doc/2.x/ but I am completely stuck...

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Henrik Killi ! I wish I knew what you had tried exactly so I could better assist you, but let's start with some hints. This is also a bit challenging to know exactly which question you're on given that they are given in a random order. But let's start with the big one first. My guess is that you'll know what I mean when I say "the one with five blanks".

Here were my first two entries for the first two blanks:

{% macro review(data) %}
...  {{ data.rating }} ...

I feel like you can fill in the rest of that given this starting point.

The import statement I would bet you got just fine and looks a lot like the line at 0:51 of this video.

{% import "courses.twig" as course %}

Finally we have the actual use case of the macro. Remember, our macro file was imported as course and inside it, there is a macro named review. We want to pass item in and we do that like this:

{{ course.review(item) }}

Hope this helps! Let me know if you need clarification or are still stuck! :sparkles: