Last active
August 29, 2015 13:58
-
-
Save clubdesarrolladores/9998563 to your computer and use it in GitHub Desktop.
Reescribir bloque de formulario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# se pone _ luego el id del campo y por ultimo label, widget, errors o row #} | |
{% block _dinamico_bundle_contactbundle_message_email_errors %} | |
{% endblock %} | |
As of Symfony 2.1 (it may work as well for 2.0 but not sure) to apply theme for collection you do this way: | |
Lets say we have a collection of products (we have multiple Product entities) | |
Controller: | |
$repository = $this->getDoctrine()->getRepository('ExampleBundle:Product'); | |
$products = $repository->findAll(); | |
$productCollection = new Products; | |
foreach ($products as $product) { | |
$productCollection->getProducts()->add($product); | |
} | |
$collection = $this->createForm(new ProductsType, $productCollection); | |
return $this->render('ExampleBundle:Default:index.html.twig', array( | |
'collection' => $collection->createView() | |
)); | |
Your theme can look like this: | |
{% block _productsType_products_entry_name_row %} | |
<div class="yourDivName">{{ block('form_widget') }}</div> | |
{% endblock %} | |
{% block _productsType_products_entry_description_row %} | |
<div class="yourDivDescription">{{ block('form_widget') }}</div> | |
{% endblock %} | |
The trick is with "entry" where twig will do the job for you to apply above changes to each row and for each field you specify | |
Hope that helps! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment