I've used both taglibs and modules significantly. I prefer each in=20
different situations for different reasons. Normally, I use taglibs=20
because they have a start tag and an end tag -- in effect, the start=20
method, content method, and end method get called in an event-driven=20
way. Modules normally have just one method which gets called.
For example, I have coded a <form> taglib which adds additional=20
features to form elements. How would you code this in a module? Would=20=
your module have a "my_form_module.textarea(name, value, default, ...)"=20=
method? How about a "my_form_module.select(name, options, value,=20
default, ...)"? Using a module would work for these, but now how would=20=
you add the master <form> tag? You could use regular HTML, but that=20
would be combining two paradigms (tags driven by modules and tags hard=20=
Taglibs make this easier by providing a simple <mytaglib:form> and=20
</mytaglib:form> pair. I just put the form controls in between the=20
tags. To me this is much more elegant and much easier to read.
Another example is a database taglib. A nice tag would be a query tag=20=
that automatically calls the body for each record returned in the=20
<mytaglib:query sql=3D"SELECT * FROM table">
print html here. the body gets run once for each row of the query=20
I'm going to post my form taglib once I get it a little more debugged. =20=
It does a lot of things that regular HTML form tags don't do. For=20
example, it automatically fills in values (if you tell it to) from the=20=
request object to inputs, textareas, and selects. This functionality=20
makes it easy to redisplay a form when validation errors occur. Simply=20=
redirect back to the page (this time showing the error), and all the=20
controls are set to what the user selected the first time.
I do feel that the example taglib that comes with spyce (called "core")=20=
isn't extremely useful because it mirrors native python constructs,=20
such as if, for, etc. I'd rather just use the python constructs inside=20=
of statements. However, more advanced taglibs, such as the one I=20
describe above, save a lot of time and make for much more elegant=20
programming. Once advanced taglibs get included in the download, it=20
will be easier for new users to get into spyce.
I have one major problem with taglibs in spyce: the context for taglibs=20=
and the context for the page are *different*. What's the reasoning=20
here? This means if you set a variable in the page you can't access it=20=
in the taglib context. To work around this, you currently have to code=20=
[[ taglib.context('x') =3D 1 ]]
New users won't understand what taglib.context() means. In any case, I=20=
think it's less than optimal. I'd rather it be:
[[ x =3D 1 ]]
I've emailed Rimon about this one, but we haven't reached any=20
conclusion on it yet. When I (and he) get some time, I'm going to take=20=
it up with him. :) I'd like to see his reasoning in making the two=20
context's different. I might even change the code to use the same=20
context and see how it works. To me, this is one of the major=20
drawbacks of spyce right now. It throws new users to Spyce off when=20
variables don't carry from one place to another.
On Tuesday, September 23, 2003, at 12:42 PM, Bowers, Brent wrote:
> I'm having difficultly seeing when/why it might be advantageous to use=20=
> Spyce active taglibs. My instinct is to not use them, since it seems=20=
> to add unnecessary complexity.=A0 But there must be some good=20
> justification for them, else why have they been created?=A0 The=20
> documentation states that using taglibs is=A0 "a matter of personal=20
> preference" and that the same results can be acheived "entirely=20
> without active tags."=A0 So, are there no scenarios where taglibs are=20=
> reasonably to be preferred?
> Thanks in advance for any insights.
Conan C. Albrecht, Ph.D.
Brigham Young University
The PGP.sig attachment is an OpenPGP (PGP/MIME) signature which can be=20=
used to verify the authenticity of this message; it serves as the=20
electronic counterpart to a handwritten signature. For more=20
information, see http://warp.byu.edu/PGPInfo.html.