Display symfony object values ​​in a branch template

Im new for Symfony / Twig, and I am having problems passing object values ​​to my branch templates.

Here is some code from my controller that shows the contents of an object:

$prevArticles = $section->getArticles(); print_r($prevArticles); die() 

Output:

 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, I pass my object to my branch template, for example:

  return $this->render('ImagineNewsletterBundle:Section:'.$builder->getTemplate(), array('prevArticles' => $prevArticles)); 

Then in my twig template I want to display the value "top_logo_advert", but it does not work:

 {% for article in prevArticles %} {{ article.top_logo_advert }} {% endfor %} 

I get an 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 
+7
symfony twig
source share
1 answer

You must access it through:

{{ article.topLogoAdvert }} or {{ article.getTopLogoAdvert() }}

Both solutions work. Next time, just remind you that properties, such as 'my_property_1' , are converted to myProperty1 in the branch engine.

+14
source share

All Articles