Skip to content

[WIP] Add section for rendering a custom prototype for collections #1998

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
wants to merge 106 commits into from

Conversation

daFish
Copy link
Contributor

@daFish daFish commented Dec 4, 2012

This PR adds an section to the prototype cookbook-article to describe how to render a custom prototype for dealing with collections.

.. code-block:: html+jinja
data-prototype="{% filter escape %}{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig' with { 'form': form.task.get('prototype') } %}{% endfilter %}"

The included `AcmeTaskBundle:Task:prototypeTask.html.twig` contains the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must use double backtricks for inline code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@daFish
Copy link
Contributor Author

daFish commented Dec 18, 2012

Is there anything left todo? /cc @weaverryan

{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig'
with { 'form': form.task.get('prototype') }
%}
{% endfilter %}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a php format aswell.

@daFish
Copy link
Contributor Author

daFish commented Jan 2, 2013

@wouterj I'll add an PHP-example along the Twig-example.

@weaverryan You mean passing tags instead of form? If so I think it would make sense when we show what the template might look like as you already suggested. I'll add that too.

@daFish
Copy link
Contributor Author

daFish commented Jan 2, 2013

I've added PHP examples and also a example prototype. But I still need to test those additions so even if it is mergable.

);

echo $view->escape($prototype);
?>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use configuration blocks for the code examples (and use the {# ... #} format for comments in the twig example):

.. configuration-block::

    .. code-block:: html+jinja

        {# src/Acme/TaskBundle/Resources/views/Taks/prototypeTask.html.twig #}
        ...

    .. code-block:: html+php

        <!-- ... -->
        ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment syntax only for html+jinja or for both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for Twig examples, more information here: http://symfony.com/doc/current/contributing/documentation/overview.html#standards (4th standard)

@weaverryan
Copy link
Member

I really want this covered in the docs, and I know this approach works (though this PR still needs some tweaks - there are some comments posted that need to be dealt with). But, is this the best way? Is there no way to theme each "task" so that when you render the tasks (or render the prototype), they use the same markup? What we're doing here is basically not form theming, but instead using our own form rendering logic when outputting the prototype and the individual fields. I guess that's ok, but if we could just theme the field, I think it would be easier.

@stof
Copy link
Member

stof commented Aug 18, 2014

When customizing the rendering of a single field, the Form component uses entry as the segment name for collection entries. It does not allow to apply a separate theme for each element of the collection separately. Symfony 2.0 was doing it (using the collection index) and it was making the rendering slow while being unusable for customization in a real app.
So the following works:

{# assuming the root form is named "myform" and the collection field inside it is "tasks" #}
{% block _myform_tasks_entry_widget %}
<tr>
    <td>{{ form_widget(form.task) }}</td>
    <td>{{ form_widget(form.dueDate) }}</td>
</tr>
{% endblock %}

@daFish
Copy link
Contributor Author

daFish commented Aug 20, 2014

@stof So, using the block would make it more usable? If this is the case I'll test it and will update the cookbook-entry accordingly.

@daFish daFish force-pushed the cookbook/prototype branch from 603e9fa to a4f53b5 Compare August 22, 2014 10:34
@daFish daFish changed the title Add section for rendering a custom prototype for collections [WIP] Add section for rendering a custom prototype for collections Aug 22, 2014
@daFish
Copy link
Contributor Author

daFish commented Sep 28, 2014

Ok, looks like I failed on rebasing. Anything I can do to fix this or would it be better to open a new PR?

@stof
Copy link
Member

stof commented Oct 2, 2014

your fail is that you rebase the symfony master branch on top of your branch instead of rebasing your branch. The way to fix this would be to rebase again, doing it with the right branch

@daFish
Copy link
Contributor Author

daFish commented Oct 7, 2014

@stof I basically followed the instructions from symfony.com. That is it, no?

@xabbuh
Copy link
Member

xabbuh commented Oct 8, 2014

@daFish Hm, do you think that you are able to solve the conflict? It's no problem if you can't do that. We can easily take your changes and rebase it for you. Just let us know what you think. :)

@daFish
Copy link
Contributor Author

daFish commented Oct 8, 2014

@xabbuh That would be great if you could that. However, I'd love to learn how to successfully rebase from master for the next time. ;)

@stof
Copy link
Member

stof commented Oct 8, 2014

@daFish are you sure you followed exactly the instructions in the doc ? To me, it looks like you ran the rebase command in your master branch instead of running it in your feature branch

@xabbuh
Copy link
Member

xabbuh commented Oct 8, 2014

@daFish Of course, I can do that tonight. Thank you for your nice contribution!

I'm pretty sure that the instructions in the documentation do actually work if you follow them step by step though.

@daFish
Copy link
Contributor Author

daFish commented Oct 8, 2014

@stof Yes, I am sure. That's what puzzles me as it wasn't the first time I did this.

@xabbuh Thank you.

@webda2l
Copy link
Contributor

webda2l commented Oct 8, 2014

Even with a rebase, this documentation is outdated, don't follow the right way of #1998 (comment) and so very little code stay valid.

https://github.com/daFish/symfony-docs/blame/ee3fc2983a220371204a9b28e25830b2a322f307/cookbook/form/form_collections.rst

@daFish
Copy link
Contributor Author

daFish commented Oct 8, 2014

@webda2l I know and this will be fixed when the rebase is done.

@xabbuh
Copy link
Member

xabbuh commented Oct 8, 2014

@daFish You can checkout the pr-1998-rebase. It is based on the 2.3 branch.

@xabbuh
Copy link
Member

xabbuh commented Nov 1, 2014

@daFish Do you have time to finish this?

@daFish
Copy link
Contributor Author

daFish commented Dec 11, 2014

@xabbuh Unfortunately I won't be able to finish this anytime soon. :(

@wouterj
Copy link
Member

wouterj commented Dec 11, 2014

@daFish thanks for noting that, we can take this over (no problem). Can you maybe provide a list of things you wanted to do? The only thing I see is rebasing, but I guess there are more things?

Thanks again for starting this!

@xabbuh xabbuh mentioned this pull request Dec 11, 2014
@xabbuh
Copy link
Member

xabbuh commented Dec 11, 2014

@daFish Thanks for starting this. I opened #4629 to finish your great work. Do you recall what you intended to do beside rebasing on 2.3?

@xabbuh xabbuh closed this Dec 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.