[Templates] Default values for Textarea field
Josh Rosenbaum
josh at infogears.com
Fri Feb 8 16:46:28 GMT 2008
Peter Sørensen wrote:
> Thanks for taking you time to reply.
>
> I sure have read the DOCS and different issues concerning the textarea field.
> You can't assign a "value" like you suggest. You have to do something like:
>
> <td><textarea name= [% field.subscribers.name] rows=.... cols=...>
> [% - FOREACH subscriber IN subscriber_members -%]
> [%- subscriber -%]
> [% END -%]
> </textarea>
>
> so I found a solution. But it is not an easy task to deal with the textarea
> field through TT. This because all the extra NL give problems.
NOTE: I don't use Catalyst or FormBuilder. So this may have 0 relevance here, but I think I understand what you guys are talking about.
What about doing this instead for those complicated cases:
------------------------------------------
[% textarea_default = BLOCK %]
[% - FOREACH subscriber IN subscriber_members -%]
[%- subscriber -%]
[% END -%]
[% END %]
<textarea name= [% field.subscribers.name] rows=.... cols=...>[% field.subscribers.field(value => textarea_default) %]</textarea>
------------------------------------------
For this simple case, I would of course use the join vmethod instead, though.
------------------------------------------
<textarea name= [% field.subscribers.name] rows=.... cols=...>[% field.subscribers.field(value => subscriber_members.join('')) %]</textarea>
------------------------------------------
One thing that could be bad is that you always have to process the default value. Maybe you could hack in a perl subroutine to pass to field.subscribers.field(value => mysub('textarea_default_block')) that would accept the name of a block to process if necessary. (This would require that the value param accepts subroutines of course.)
Roughly mysub would look like:
sub mysub{
my ($block_name) = @_;
return sub{
return $tt->context->process($block_name)
}
}
Just throwing ideas out there for you. They may need refinement.
-- Josh
More information about the templates
mailing list