[html-formfu] Passing values to from the config to custom templates

Carl Franks fireartist at gmail.com
Sat Apr 19 17:51:26 BST 2008


On 18/04/2008, Tobias Henöckl <hoeni-formfu at sisyphus.de> wrote:
>
>  I'm setting up a custom, tt-rendered, form element and need to pass a
> configuration from the YAML file straight to the rendered template.

Every form and element has it's own stash, which is just a hashref
that you can use for things like this.
For example:

    - type: CountryChooserGeneric
      name: country
      stash:
        countrydefaultsfrom:
          - param_country
          - session_country
          - domain_country

Then you can access that data in your template with something like:
    [% self.stash.countrydefaultsfrom %]

(I forget off-hand to to deref' an array-ref in TT)

>  Having a closer look, I found "self" in the controller just beeing a simple
> hash containing some values instead of beeing the HTML::FormFu::Element
> object himself.

Is this the result of $form->render - inside a template?

There's a lot of things that need calculated, such as what value to
use for each field, that means it's not practical to just use the
original elements.
Originally, we created HTML::FormFu::Render::Element objects, which
wouldn't effect the original HTML::FormFu::Element objects, but
(mainly for efficiency) we switched to just creating data structures.
The 'preferred' way to render now is just to use the internal string
renderer, which especially doesn't need objects. - That said, using
the template files such as you are, is still fully supported.

There was talk a few months ago about providing access to the original
objects, for each
element with something like [% self.original_object %] - but I can't
remember whether anybody did it or not.
Although you shouldn't need it for this, as your have the stash, if
this feature hasn't been implemented yet and you want to use it, feel
free to provide a patch (with tests)!

Cheers,
Carl



More information about the HTML-FormFu mailing list