Tengo un controlador, una macro twig y la plantilla principal donde se importa la macro. Me gustaría enviar una matriz en mi macro y para cada fila de mi tabla quiero mostrar sus datos.
Una línea se compone de: título, descripción, img, tipo
El controlador :
/** * @Route("/realisations", name="realisations") * @Method({"GET"}) * * @return \Symfony\Component\HttpFoundation\Response */ public function realisationsAction() { return $this->render('MyBundle:page:realisations.html.twig', $datas = array('type' => 'The type', 'img' => 'test.jpg', 'titre' => 'Test', 'description' => 'The description')); }La plantilla principal:
{% import "MyBundle:macros:realisationsMacros.html.twig" as macros %} {{ macros.realisations(datas) }}La macro:
{% macro realisations(datas) %} {% for data in datas %} <div class="project {{ data.type }} isotope-item" style="position: absolute; left: 0; top: 0; transform: translate3d(0px, 0px, 0px);"> <div class="content"> <div class="image"> <img src="{{ asset('bundles/jsmetallerie/img/realisations/'~ data.type ~'/13.png') }}" alt="{{ data.titre }}"> <div class="item-hover"> <ul class="item-icons"> <li><a href="{{ asset('bundles/jsmetallerie/img/realisations/'~ data.type ~'/'~ img) }}" data-fancybox><i class="fa fa-search"></i></a></li> <li><a href="{{ path('jsm_realisation_projet') }}"><i class="fa fa-link"></i></a></li> </ul> </div> </div> <span class="h6">{{ data.titre }}</span> <p>{{ data.description }}</p> </div> </div> {% endfor %} {% endmacro %}El error de Symfony es: "La variable "datos" no existe".
creo que el error viene de crear mi tabla en el controlador pero no se como crearla correctamente
Gracias por adelantado
simplemente pase una matriz con una clave llamada 'datos' como ejemplo:
$params = array( 'datas' => array('type' => 'The type', 'img' => 'test.jpg', 'titre' => 'Test', 'description' => 'The description') ); return $this->render('MyBundle:page:realisations.html.twig', $params);Espero que esto ayude