Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mdpatrick opened this issue Sep 12, 2011 · 4 comments
Closed

Comments

@mdpatrick
Copy link
Contributor

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?
@mdpatrick
Copy link
Contributor Author

Aha! This might be relevant for a cookbook article... from jstout_ on IRC:

http://pastie.org/2522598

@imikay
Copy link

imikay commented Feb 28, 2012

Six months later, there is still not a solution to this.

@weaverryan
Copy link
Member

Is this related to symfony/symfony#2806?

If so, we will just need to add a note to the docs after this solution is merged in. If there are other pieces missing, please let me know. The form collection cookbook was just heavily updated, but I think there's still some room for details on theming certain items.

Thanks!

@weaverryan
Copy link
Member

I think this may be addressed in 2.1, where the prototype field has changed from $$name$$ to __name__.

If I'm mistaken, someone can speak up and we'll re-open the issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants