[Bese-devel] Defining new TAL tags (Was: strings as parameters in TAL templates)
Marco Baringer
mb at bese.it
Fri Feb 3 15:44:44 UTC 2006
> Jan Rychter wrote:
>> How do you handle string parameters in TAL tags? Specifically, quoting?
>>
>> I've tried this:
>>
>> <tal:tal tal:content='(inline-image "dir1/crw_1122.jpg")' />
>>
>> but it results in garbage generated after the tag is replaced, I get
>> extra:
>> /></a
>> >
this is as good a time as any to describe the (probably too many) steps
required to create your own tal tag:
1) define a yaclml tag macro which does what you want:
(deftag-macro my-package:my-img (&attribute image-name)
(rebinding (image-name)
`(<:a :href (inline-image ,image-name)
(<:as-html (inline-image ,image-name)))))
[nb: don't forget the &attribute if you want to be able to use this from
a tal file]
2) so now we could use our tag from regular code and what we need to do
is tal how to find it and associate it with a tag in an xml file:
(push (cons "http://example.com/tal/" (find-package :my-package)
yaclml:*uri-to-package*)
3) within a tal file we can now use our tag if we setup the proper
namespaces:
<html xmlns:my-app="http://example.com/tal/">
...
<my-app:my-img image-name="dir1/crw_1122.jpg"/>
...
nb: the image-name attribute need not be prefixed with a particular
namespace (though it probably should). unless there's a tal handler for
that particular attribute it'll get coalesced into the keyword package
no matter what package was specified in the tal file.
not that you asked for this, but hope it helps anyway.
--
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen
More information about the bese-devel
mailing list