0

If I get an array of types using Doctrine like this:

$types = $this->getDoctrine()
    ->getRepository('Model:Type')
    ->findAll();

And then pass $types to the Twig template (as 'types') and loop through it:

{% for type in types %}
-- WHAT GOES HERE?
{% endfor %}

I've been doing a bit of reading, and I'm not even sure if this is possible? Can I only pass associative arrays through to Twig or do arrays of objects work? And if so, how can I access the public functions of the object in Twig?

Basically I want to call getName(), getUsage(), getId() and a few other public functions on the Type object.

Thanks

1 Answer 1

3

Then you could do it like below:

{% for type in types %}
  {{ type.name }}
  {{ type.usage }}
  {{ type.id }}
{% endfor %}

{{ type.getName() }} also works, it's same with {{ type.name }}.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.