On 10/20/10 11:40 AM, Lukas Kahwe Smith wrote:
Hi,

Bundle best practices for templates :
-------------------------------------------------

So we are looking at making use of DoctrineUserBundle, but feel like
there is a bit of work to do in order to make the default controller
and templates.

First up by copying the default templates over into my Application
dir, I can overload templates. However for this to be useful, it
would be a good idea to separate extends from the rest. For example:
http://github.com/knplabs/DoctrineUserBundle/blob/master/Resources/views/Session/new.php

A template can use a layout (to be able to reuse things), but it must not extend a layout that defines the main HTML structure.

For this specific case, and probably for many more, I think the bundle should not provide a default template. It should provide a way to configure the template you want to use instead and perhaps provide a small example of a simple template in the documentation (to show the mandatory fields, names, ...). We can also imagine that a command can generate this default simple template in one of your bundle to get you started faster. That way, it's up to the end-user to cook the HTML the way he wants.

If the template will be complex to create, the bundle should then provide macros, helpers, partials, ... to ease the integration.

If we do that, I'm pretty sure that all your points below are taken care of.

Fabien

 Here it would be good to to have one template that does the extends
and another one that contains just the form. Potentially we could
also make use of twig macro's here so that the template with the
extends doesnt need to use include? Of course this requires migrating
to twig, which I guess is the best practice we want to use for
Bundles anyway.

Also we want to take great care in defining some best practices for
the HTML markup too. But especially for forms we should try to use
the form API to the "max". Aka not render widgets, but render
formgroups, because this then goes through the TwigBundle, which
allows easily replacing of how things should be listed (for example
using div's , like in the above example, or lists or sticking with
the default table approach).

Injecting custom variables into a 3rd party Bundle:
-------------------------------------------------------------------

Now the bigger issue is that how can I get some custom variables into
my layout. For example to display the menu header. Now one approach
would be to essentially make an instance of the Bundle controller,
for example DoctrineUserBundle\SessionController, inside an
application Controller. Then I could with the above tools simply make
the layout do nothing, so that I just get the form HTML. Then I can
then render this HTML with some custom logic into the actual layout
of my application.

This however means that for every method I want to expose in a 3rd
party Bundle, I have to write a wrapper method just so that I can
inject a few things into the layout. Now Maybe there should be an
event to hook into when a Controller loads a template. My application
could then connect to this event to do some processing to generate
various variables necessary inside my applications layout template.

regards, Lukas Kahwe Smith [email protected]




--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to