You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "WATKINS, Andy, FM" <An...@rbos.com> on 2001/01/02 18:21:37 UTC

Equivalent to webmacro htmlescape

Many of the String variables I place within the template
cantain &'s and <'s.

In webMacro I can globally force all returned strings to 
be escaped with the #htmlescape directive.

Can I do this in Velocity? Many template engines have HTML 
escaping enabled by default as this is the most useful.

Andy


********************************************************************
This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorised to
retain, read, copy or disseminate this message or any part of it.
********************************************************************

Re: Equivalent to webmacro htmlescape

Posted by Christoph Reck <Ch...@dlr.de>.
Jason van Zyl wrote:
> We are planning to move all useful tools into a single
> location soon and make them available as a useful set
> of context tools and the Escape class will be one
> of them.

Will this include most/all of the methods I sent in the
"EncodeXXX context tools" mail within the "Rendering Velocity 
Templates with Texen" thread?

I do have some other usable ContextTools (see "[PROPOSAL] 
generic context tools" in the turbine list. These seem more
fit for the application level that for Vel.

I guess that it would be good to create a Turbine and/or 
Velocity utility library containing such tools (and VMs).
out of which users can pick what they need to avoid re-
inventing the wheel. This library should not be restricted
to Vel, but should contain hints with which templating
engine the classes/files work.

:) Christoph

Re: Equivalent to webmacro htmlescape

Posted by Jon Stevens <jo...@latchkey.com>.
on 1/2/2001 9:44 AM, "Jason van Zyl" <jv...@periapt.com> wrote:

> There is an Escape.java class that is currently used
> in Anakia to do this. You can simply grab that class
> place it in the context and go!
> 
> context.put("escape", new Escape());
> 
> and use it in your template as
> 
> $escape.getText($stringToEscape)
> 
> We are planning to move all useful tools into a single
> location soon and make them available as a useful set
> of context tools and the Escape class will be one
> of them.
> 
> jvz.

Maybe it would be a good idea to allow #macro's to be passed in a value if
they have a #end. Therefore, it would be easy to do something like this:

context.put("escape", new Escape());

-----------
#macro (htmlescape $pass)
$escape.getText($pass)
#end
-----------

Then in your page:

#htmlescape
<>""
#end

It would make it really easy to emulate #defines that way and seems to be a
cleaner way of implementing things than making everyone create their own
#directives like WM does. :-)

I would be +1 to have it be severely restricted though. For example, you can
only pass in one argument and that argument can only be a String.

-jon

-- 
Honk if you love peace and quiet.


Re: Equivalent to webmacro htmlescape

Posted by Jason van Zyl <jv...@periapt.com>.

On Tue, 2 Jan 2001, WATKINS, Andy, FM wrote:

> Many of the String variables I place within the template
> cantain &'s and <'s.
> 
> In webMacro I can globally force all returned strings to 
> be escaped with the #htmlescape directive.
> 
> Can I do this in Velocity? Many template engines have HTML 
> escaping enabled by default as this is the most useful.

There is an Escape.java class that is currently used
in Anakia to do this. You can simply grab that class
place it in the context and go!

context.put("escape", new Escape());

and use it in your template as

$escape.getText($stringToEscape)

We are planning to move all useful tools into a single
location soon and make them available as a useful set
of context tools and the Escape class will be one
of them.

jvz.