.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTML::FormHandler::Manual::Templates 3pm" .TH HTML::FormHandler::Manual::Templates 3pm "2022-03-25" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTML::FormHandler::Manual::Templates \- using templates .SH "VERSION" .IX Header "VERSION" version 0.40068 .SH "SYNOPSIS" .IX Header "SYNOPSIS" Manual Index .PP Documentation on templates to use with HTML::FormHandler .SH "Using templates" .IX Header "Using templates" There is a FormHandler Template Toolkit rendering role at HTML::FormHandler::Render::WithTT, with a testcase in t/render_withtt.t. Normally, however, it probably won't make much sense to use both a \&\s-1TT\s0 parser in FormHandler, and a separate one for the \*(L"complete\*(R" templates, so the \s-1TT\s0 renderer is mainly useful for tests, or as an example of how to do \s-1TT\s0 rendering with \s-1HFH.\s0 You should create a template to render your form and then pass the template name and a template variable containing your form object to your templating or view engine, in whatever way you normally do that. If you want to use the 'process_attrs' function, you need to set that in your template variables too. .PP A common way of using FormHandler with templates is to use the template for layout, specifying the divs and spans and wrappers, and then use the form object to render just the input fields. .PP In your form: .PP .Vb 1 \& has \*(Aq+widget_wrapper\*(Aq => ( default => \*(AqNone\*(Aq ); .Ve .PP In your Catalyst controller: .PP .Vb 1 \& $c\->stash( form => $form, template => \*(Aqform.tt\*(Aq ); .Ve .PP \&..or do the equivalent for your web framework/view. .PP In a form template (form.tt in the previous controller example): .PP .Vb 8 \&
\&
\& My Foo \& [% form.field(\*(Aqfoo\*(Aq).render %] \&
\&
[% form.field(\*(Aqbar\*(Aq).render %]
\& [% form.field(\*(Aqsave\*(Aq).render %] \&
.Ve .PP However, you can also render entirely with templates. There are lots of different ways to set up templates. There are sample templates installed in FormHandler's 'share' directory. These templates are now organized more-or-less similarly to the widget roles, with 'field', \&'wrapper', and 'form' directories, but many other organizations are possible. .PP There is also a template which combines the template rendering code into one file, 'share/templates/form/form_in_one.tt'. You can copy this template into your own \s-1TT\s0 directories, perhaps as form.tt, and then specify it as the template for your Catalyst actions. You can customize it by adding additional widget and widget_wrapper blocks, and then setting those in your field definitions. .PP Note that widget names usually are camelcased, like the Moose roles that implement them in the Widget directory. You may want to use the non-camelcased widget/wrapper names in your \s-1TT\s0 templates, using the \f(CW\*(C`$field\->uwidget\*(C'\fR (un-camelcased widget name) and \&\f(CW\*(C`$field\->twidget\*(C'\fR (un-camelcased widget name + '.tt') convenience methods. ('MySpecialWidget' is the equivalent of 'my_special_widget') .PP .Vb 2 \& has_field \*(Aqmy_field\*(Aq => ( widget => \*(AqMySpecialWidget\*(Aq ); \& has_field \*(Aqanother_field\*(Aq => ( widget => \*(AqYetAnotherWidget\*(Aq ); .Ve .PP And include them in a generic template: .PP .Vb 1 \& [% PROCESS widget/form_start.tt %] \& \& [% FOREACH f IN form.sorted_fields %] \& [% PROCESS widget/${f.twidget} %] \& [% END %] \& \& [% PROCESS widget/form_end.tt %] .Ve .SH "Field attributes" .IX Header "Field attributes" If you want to use the 'process_attrs' function to pull in \s-1HTML\s0 attributes for the input elements, wrappers, and labels, you would need to pass that function into your \s-1TT\s0 setup. See HTML::FormHandler::Render::WithTT for an example: .PP .Vb 2 \& use HTML::FormHandler::Render::Util (\*(Aqprocess_attrs\*(Aq); \& $c\->stash( process_attrs => &process_attrs ); # or add to TT vars in your view \& \& \& .Ve .SH "Sample templates" .IX Header "Sample templates" The following is copied from the provided share/templates/form/form_in_one.tt file, as an example. Note that some fields, like form actions of 'submit' & 'reset', don't use the 'fif' value, but just the plain field value. .PP .Vb 10 \& [% PROCESS form_start \-%] \&
\& [% FOREACH err IN form.form_errors \-%] \& [% err %] \& [% END \-%] \&
\& [% FOREACH f IN form.sorted_fields \-%] \& [% WRAPPER "wrapper_${f.uwrapper}" \-%][% PROCESS "${f.uwidget}" \-%][% END \-%] \& [% END \-%] \& [% PROCESS form_end \-%] \& \& [% BLOCK form_start \-%] \& \& [% END \-%] \& \& [% BLOCK form_end \-%] \& \& [% END \-%] \& \& [% BLOCK button \-%] \& \& [% END \-%] \& \& [% BLOCK checkbox \-%] \& [%~ ~%] \& [% END \-%] \& \& [% BLOCK checkbox_group \-%] \& [% FOR option IN f.options \-%] \& \& [% END \-%] \& [% END \-%] \& \& [% BLOCK compound \-%] \& [% FOREACH sf IN f.sorted_fields \-%] \& [% outerf = f; f = sf; \-%] \& [% WRAPPER "wrapper_${f.uwrapper}" %][% PROCESS "${f.uwidget}" \-%][% END \-%] \& [% f = outerf \-%] \& [% END \-%] \& [% END \-%] \& \& [% BLOCK hidden \-%] \& \& [% END \-%] \& \& [% BLOCK password \-%] \& \& [% END \-%] \& \& [% BLOCK radio_group \-%] \& [% FOR option IN f.options \-%] \& \& [% END \-%] \& [% END \-%] \& \& [% BLOCK repeatable \-%] \& [% FOREACH rf IN f.sorted_fields \-%] \& [% outerrf = f; f = rf; \-%] \& [% WRAPPER "wrapper_${f.uwrapper}" %][% PROCESS "${f.uwidget}" \-%][% END \-%] \& [% f = outerrf \-%] \& [% END \-%] \& [% END \-%] \& \& [% BLOCK reset \-%] \& \& [% END \-%] \& \& [% BLOCK select \-%] \& \& [% END \-%] \& \& [% BLOCK submit \-%] \& \& [% END \-%] \& \& [% BLOCK text \-%] \& \& [% END \-%] \& \& [% BLOCK textarea \-%] \& \& [% END \-%] \& \& [% BLOCK upload \-%] \& \& [% END \-%] \& \& [% BLOCK wrapper_simple \-%] \& \& [% IF f.do_label %][% PROCESS label %][% END \-%] \& [% content \-%] \& \& [% END \-%] \& \& [% BLOCK label \-%] \& \& [% END \-%] \& \& [% BLOCK wrapper_wrap_label \-%] \& \& \& [%~ content ~%][%~ f.label %] \& \& \& [% END \-%] \& \& [% BLOCK wrapper_none \-%] \& [% content %] \& [% END \-%] \& \& [% BLOCK wrapper_fieldset \-%] \& [% f.label %] \& [% content \-%] \& \& [% END \-%] .Ve .SH "AUTHOR" .IX Header "AUTHOR" FormHandler Contributors \- see HTML::FormHandler .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Gerda Shank. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.