Skip to content

Theming an embedded form (collection/prototype). Possible with Twig at all? #696

Closed
@mdpatrick

Description

@mdpatrick

I was unable to find an elegant solution to this. It's mentioned in the Symfony2 google group as well. If it's possible it should be mentioned in the docs. If it's not possible, let me know and I'll open this as an issue elsewhere.

http://groups.google.com/group/symfony2/browse_thread/thread/b3686bbfe561842c?pli=1

With a combination of Googling and reading the docs, I've managed get 
a form with an embedded 1:M collection up and running, but now I'm 
stumped.  What I want to do is theme a single field in an _embedded_ 
form. 

I've successfully themed single fields on the parent form, but what I 
expected to work on an embedded form isn't panning out. 
Say I have a parent form of type Company and a collection of embedded 
forms of type Facility which are inserted into the dom via JS using 
the collection type's form prototype. 

Say I want to customize just the 'name' field in the parent, Company 
form, as demonstrated here: 
http://symfony.com/doc/current/cookbook/form/form_customization.html#... 

If the ID is company_name I create a twig block with a name of 
_company_name_widget and it works perfectly. 

Now say I want to customize only the address field of each Facility in 
the collection.  The ID of that field in the prototype is 
company_facilities_$$name$$_address, and my JS would replace the $$name 
$$ with an index.  I've tried creating twig blocks with names with 
different combinations of 'companies', 'facilities', 'address' and 
underscores to see if any would register and so far no dice. 
Theoretically, if it follows the pattern, a twig block name of 
_company_facilities_$$name$$_address_widget should work, but twig 
isn't a fan of '$' in block names. 

So is this possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions