Luke Meyer wrote:
I'm trying to write a plugin that prints out various error messages to a
template's specification (with some of my own magic, of course). I'm
sure I'm not the first to do this kind of thing so hopefully someone
will point me in the direction of the painfully obvious way this should
be handled. Here's the template code I'm expecting to work:
<h3>Login creation</h3>
[% BLOCK errmsg %]
<div class="errmsg">[% HTML.esc(text) %]</div>
[% END %]
[% USE myform = ParamShuttle(form.user_create, template = errmsg);
#note: passing the BLOCK above into the plugin for re-use. %]
[% myform.errors() #general errors %]
<form method="post">
[% FILTER fillinform fobject => form.user_create %]
[% myform.errors("login") #specific errors %]
<div class="row">
<span class="label">Login name you want:</span>
<input type="text" name="login" size="50" />
</div>
[% myform.errors("email") #specific errors %]
<div class="row">
<span class="label">Email address for account:</span>
<input type="text" name="email" size="50" />
</div>
[% myform.errors("visible_name") #specific errors %]
<div class="row">
<span class="label">Choose a visible name:</span>
<input type="text" name="visible_name" size="50" />
</div>
[% END #fillin filter before password %]
...
In addition to passing the BLOCK at plugin creation, I'd like to be able
to pass it as an optional parameter on a given method call against the
plugin (to override for specific cases). Of course, none of this works,
because a BLOCK declaration isn't just a variable that gets put in the
stash to be passed around.
Problems with the obvious approaches I've already considered:
1) Extract the "errmsg" block to a file and pass the file name. Sure,
that works, but it kind of sucks. I shouldn't have to go to another
file to see what I'm working with, if I don't want it that way.
2) Implement as a filter instead of a plugin. But I want to use the
same block template multiple times (for multiple fields), and as far as
I can tell there's no way to have a FILTER do that -- you have to
specify the block it's filtering for each use.
3) Have the plugin just return the list of errors and let the template
process them through the block with some kind of [% FOR ... %] loop.
Sure, that works, but again it sucks. I'd like the plugin to do that work.
Thanks in advance for ideas/pointers.
-Luke
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates
Hi Luke,
You might try to pass the block by name instead.
ie:
[% USE myform = ParamShuttle(form.user_create, template = 'errmsg');
#note: passing the BLOCK above into the plugin for re-use. %]
Then process the block inside your plugin, since you can call process with the
name of a block.
ie:
return $context->process($block_name);
To pass the 'text' for the block, just set it using the stash above the
process, or as the second parameter in the process statement.
Hope that helps ya.
-- Josh
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates