You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Carsten Burghardt <cb...@emedia-consult.de> on 2001/04/19 19:07:33 UTC
Create new tags?
Hi there,
I´m pretty new to Velocity but I want to give it a try.
Is it possible to define new tags?
I have several XML-like tags that are embedded in HTML pages , e.g.
<MORE>Here is a link</MORE> and these should be parsed and substituted with
HTML code. I have written my own parser for that but I want to get rid of it.
Thanks folks!
--
Carsten Burghardt
eMedia Consult
email: cb@emedia-consult.de
WWW: http://www.emedia-consult.de
PGP: http://www.emedia-consult.de/Carsten_Burghardt.asc
Re: Create new tags?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Carsten Burghardt wrote:
>
> Hi there,
>
> I´m pretty new to Velocity but I want to give it a try.
> Is it possible to define new tags?
The answer is yes, and you have three choices. FIrst, we don't call
them 'tags', as that's a JSP concept. The three ways of extending your
content, analgous to tags are
1) Just write classes that produce output. When your servlet or other
code places them in the context, you can access them in the template
like :
$yourclass.callYourMethod()
and could pass args if you wish. However, it's not recommended that you
output HTML this way.
2) Another way, more appropriate for outputting HTML or other 'view'
layer output is a mechanism called 'Velocimacros'. These are macro-like
declarations that allow you to defined a parameterized bit of view-layer
code. To guess at your <MORE> exapmle, you could define as :
#macro( more $arg )
Click to see <a href="$arg">more...</a>
#end
and then you can use it in your template as
#more( "MyServlet?article=123" )
or something.
3) The final, least recommended way is to write 'directives'. These
are the actual 'language' elements in Velocity. The general rule is if
you need to write a directive, first see if you can use a velocimacro.
If not, then a class placed in the context. If you still feel you have
to use a custom directive, stand back and rethink the problem, because
you don't :)
> I have several XML-like tags that are embedded in HTML pages , e.g.
> <MORE>Here is a link</MORE> and these should be parsed and substituted with
> HTML code. I have written my own parser for that but I want to get rid of it.
Velocity should fit the bill.
geir
--
Geir Magnusson Jr. geirm@optonline.net
Developing for the web? See http://jakarta.apache.org/velocity/
Re: Create new tags?
Posted by Jon Stevens <jo...@latchkey.com>.
on 4/19/01 10:07 AM, "Carsten Burghardt" <cb...@emedia-consult.de> wrote:
> Hi there,
>
> I´m pretty new to Velocity but I want to give it a try.
> Is it possible to define new tags?
> I have several XML-like tags that are embedded in HTML pages , e.g.
> <MORE>Here is a link</MORE> and these should be parsed and substituted with
> HTML code. I have written my own parser for that but I want to get rid of it.
>
> Thanks folks!
You are in the totally wrong forum. Maybe you should try the Struts group.
-jon
--
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>