[development] theming in D7

Randy Fay randy at randyfay.com
Sun Oct 24 16:53:39 UTC 2010


A form theming example would be a nice addition to the form_example if you'd
be interested in posting a patch.

Thanks,

-Randy

On Sun, Oct 24, 2010 at 10:45 AM, Bob Hutchinson <hutchlists at midwales.com>wrote:

> On Saturday 23 October 2010, Earl Miles wrote:
> > On 10/22/2010 1:56 PM, Bob Hutchinson wrote:
> > > In D7 I get somewhat different behaviour:
> > >
> > > If I do not create an entry in the theme registry, all works as
> expected,
> > > but if I do, things start to behave oddly.
> > >
> > > function mymodule_theme() {
> > > ....
> > >
> > >     'mymodule_thingy_form' => array(
> > >
> > >       'variables' => array(
> > >
> > >         'form' => NULL,
> > >
> > >       ),
> > >
> > >     ),
> >
> > In D7 the above should actually be:
> >
> >      'mymodule_thingy_form' => array(
> >        'render element' => 'form',
> >
> > > ....
> > > }
> > > and create a function
> > > function theme_mymodule_thingy_form($variables) {
> > >
> > >   $form = $variables['form'];
> > >   $output = drupal_render($form);
> > >   return $output;
> > >
> > > }
> >
> > You should use either render() or drupal_render_children() rather than
> > drupal_render(). So far as I could figure out, drupal_render() should no
> > longer be used inside theme functions. You use render() to render a
> > specific element, and drupal_render_children() to render all the
> > children but NOT the element (which is what you want when attempting to
> > render $form since that is currently being rendered).
>
> I ran some trials using form_example from
> http://drupal.org/project/examples
> I found that indeed I should not use drupal_render()  inside theme
> functions,
> drupal_render_children() works fine.
> I also found that using drupal_get_form() within a function (as opposed to
> in
> a menu) requires the output of drupal_get_form() to be run through
> render(),
> otherwise the form is not complete. The theme (defined with 'render
> element')
> is picked up automatically, the same as it is when calling
>  drupal_get_form()
> directly in a menu $item.
>
> Thanks for your help.
>
> --
> -----------------
> Bob Hutchinson
> Midwales dot com
> -----------------
>



-- 
Randy Fay
Drupal Module and Site Development
randy at randyfay.com
+1  970.462.7450
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101024/543ec9ad/attachment.html 


More information about the development mailing list