You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Eddie <po...@hotmail.com> on 2001/03/19 12:50:52 UTC

Html encoding ?

Hellu,

How do you encode special characters like "&" to proper readable html text with velocity ??
Does velocity already have a utility for this ? I noticed that velocity doesn't do this automaticaly.

I have a little class, called WebUtil, with a class method (note: not an object method) called htmlEncode. How can I use this in my velocity template ?

Regards,
Ed Bras


Re: Html encoding ?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Eddie wrote:

> >
> > When you say 'class not object' do you mean its static?  You still
> > should be able to make one of those classes and place it into the
> > context, right?
> 
> Yep, it's a static class, whereas with ctx.put() I can only push objects, so
> how can I use a method of this static class in my template ?

How about a simple wrapper that does the calls for you?

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Html encoding ?

Posted by Eddie <po...@hotmail.com>.
----- Original Message -----
From: Geir Magnusson Jr. <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Monday, March 19, 2001 1:55 PM
Subject: Re: Html encoding ?


> > Eddie wrote:
> >
> > Hellu,
> >
> > How do you encode special characters like "&" to proper readable html
> > text with velocity ??
> >
> > Does velocity already have a utility for this ? I noticed that
> > velocity doesn't do this automaticaly.
> >
> No, and the reason is that Velocity wasn't specially built for HTML, but
> rather is general in nature (althought great for the web).
>
> > I have a little class, called WebUtil, with a class method (note: not
> > an object method) called htmlEncode. How can I use this in my velocity
> > template ?
>
> When you say 'class not object' do you mean its static?  You still
> should be able to make one of those classes and place it into the
> context, right?

Yep, it's a static class, whereas with ctx.put() I can only push objects, so
how can I use a method of this static class in my template ?

Regards,
Ed Bras

Re: Html encoding ?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
> Eddie wrote:
> 
> Hellu,
> 
> How do you encode special characters like "&" to proper readable html
> text with velocity ??
>
> Does velocity already have a utility for this ? I noticed that
> velocity doesn't do this automaticaly.
>
No, and the reason is that Velocity wasn't specially built for HTML, but
rather is general in nature (althought great for the web).

> I have a little class, called WebUtil, with a class method (note: not
> an object method) called htmlEncode. How can I use this in my velocity
> template ?

When you say 'class not object' do you mean its static?  You still
should be able to make one of those classes and place it into the
context, right?

If not, make a littls wrapper class that calls it, and put that into the
context

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Html encoding ?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
>From Arik Levin <ar...@trendline.co.il>  in HTML : 

(No HTML to the list if it can be avoided :)

> I don't know if velocity is prepare to this.. but 
> you can encode with javascript:
> 
>    like this..
> 
>        <script>
>                    var x = escape("&");
>                    unescape(x);
>       </script>

That might work, but you can still put your HTML encoder tool into the
context, and just use it.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/