Displaying symfony object values in twig template
symfony, twig
Solution
You must access it via :
`{{ article.topLogoAdvert }}` or `{{ article.getTopLogoAdvert() }}`
Both solutions works. Next time, just reminder that properties like `'my_property_1'` is converted into `myProperty1` in the twig engine.
Problem
Im new to Symfony / Twig and am having problems passing object values to my twig templates. Here is some of my controller code that shows the content of the object: ``` $prevArticles = $section->getArticles(); print_r($prevArticles); die() ``` Displays: ``` Array ( [0] => Imagine\NewsletterBundle\Entity\Article Object ( [id:protected] => [title:protected] => [headline:protected] => [link:protected] => [image:protected] => [excerpt:protected] => [check:protected] => [attachment:protected] => [field1:protected] => [field2:protected] => [field3:protected] => [magazines:protected] => [top_logo_advert:protected] => /uploaded_images/cece0b1859ea2b1af95f1f274620ba77.jpg [top_logo_alt:protected] => Picture of blomange [top_logo_link:protected] => www.google.com ) ) ``` So then I pass my object to my twig template like so: ``` return $this->render('ImagineNewsletterBundle:Section:'.$builder->getTemplate(), array('prevArticles' => $prevArticles)); ``` Then in my twig template I want to display the value of 'top_logo_advert' but its not working: ``` {% for article in prevArticles %} {{ article.top_logo_advert }} {% endfor %} ``` I get the error message: ``` Method "top_logo_advert" for object "Imagine\NewsletterBundle\Entity\Article" does not exist in ImagineNewsletterBundle:Section:build_advert.html.twig at line 62 ```