You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Stuart Churchill <SC...@caluk.com> on 2001/09/12 15:35:13 UTC

Escaping VTL elements

Hi folks,

I'm using Velocity to generate Java classes, servlets and other templates,
based upon a given database schema. Up to now, everything was tickety-boo,
but I'm having some problems writing templates that get parsed to produce
other templates.

The first problem was how to escape a comment directive ('##') in my source
template, so that it would be written out correctly to my destination
template. At the moment, the undernoted code works, but is there another way
?

#set ($hash = "#")
$hash$hash
$hash$hash This is a comment to appear in the output
$hash$hash

Secondly, an escaping problem that I've not yet found a workaround for. My
destination template should contain a reference '$!BreederSurname'. My
source template includes a reference '$column.getName()', which in this
instance returns the value "BreederSurname". How do I combine the two ?

I've trawled the documentation, and the archives, but the closest I could
find was a message from Geir in December last year, ("more escaping fun"),
which touched on the issue, but didn't solve it for me.

   Cheers,

       Stu.

   Lead Developer  -  Computer Applications Ltd



Re: semi-on-topic question

Posted by Jon Stevens <jo...@latchkey.com>.
on 9/19/01 1:26 AM, "Gabriel Sidler" <si...@teamup.ch> wrote:

> I am currently working on a Struts/JSP project. This forces me to understand
> in
> detail the integration of JPS with Struts. This will help me to better
> understand
> the Velocity/Struts integration issues. I will look into this integration
> again 
> after I finish the current project at the end of October. I'll keep the list
> posted.
> 
> Gabe

Great! Thanks for working on this!

-jon


Re: semi-on-topic question

Posted by Gabriel Sidler <si...@teamup.ch>.
John McNally wrote:
> 
> How have the developers on Struts reacted to talk of integrating
> Velocity as a view?  I thought a major reason for the formation of
> Struts was that Turbine allowed both jsp and velocity view layers and
> this was considered too complex and Struts was to be a single view
> technology only (jsp).
> 
> john mcnally

John,
I have not made this public on the Struts list. I want this to be well
worked out and well documented before I talk about it to the Struts people. 
I don't expect too many cheers....

I did some experiements with Velocity and Struts to find out if an integration 
would be possible and how much effort it would take. The result was that after 
a weekend I had the basics working without any changes to Struts. However,
as Geir pointed out correctly, there are some more advanced features in Struts 
that require more thought. To get the full functionality of Struts with Velocity 
probably would require the development of some context tools or macros. From 
what I understand now, I don't see any serious difficulties (but maybe I don't 
unterstand it fully :-). 
I am currently working on a Struts/JSP project. This forces me to understand in
detail the integration of JPS with Struts. This will help me to better understand
the Velocity/Struts integration issues. I will look into this integration again 
after I finish the current project at the end of October. I'll keep the list
posted.

Gabe

---------------------
Eivycom
Technoparkstrasse 1
8005 Zurich
Switzerland

sidler@teamup.com
+41 1 845 18 00
---------------------



> Gabriel Sidler wrote:
> >
> > piero de salvia wrote:
> > >
> > > hi guys,
> > >
> > > i have a question that only marginally relates to
> > > Velocity, but it helps people that build sites with
> > > Velocity I think.
> > >
> > > what is the correct-truly-OO way of invoking methods
> > > [besides Turbine] in response to form submittals ?
> > >
> > > Is it reflection? That means form submits should be
> > > named after Java methods. this seems to me poor
> > > encapsulation, or brittle at least. Looking them up in
> > > a hash ? And even so, after you look it up, say you
> > > get a pointer to a class that has to do an if else
> > > chain, right? Poor OO again.
> >
> > Apache Struts maps URLs to instances of so called action
> > classes. Action classes can be seen as request handlers or
> > request targets. Its the hastable approach.
> > Whether you have to use if-else-chains within the action
> > classes depends on how fine grained your action classes are.
> > I find its about finding a good compromise between the number
> > of action classes and some if-else chains.
> > For more complex applications, Struts offers an action class
> > that uses reflection to dispatch requests to methods, thereby
> > basically combining the hashtable approach with the reflection
> > approach.
> >
> > One very useful feature of Struts in this context is that
> > one can define aliases for action classes. This introduces
> > an optional layer of indirection in the mapping of URLs to
> > action classes. I believe this would address some of your
> > concerns about poor encapsulation.
> >
> > I am currently working on a Struts-based project and find it
> > a relatively simple and lightweight web app framework that
> > provides strong MVC concepts.
> >
> > Unfortunately the view component of Struts is currently very
> > much JSP centric. However, I did spend some time a while ago
> > to look into integration of Velocity/WebMacro with Struts. I know
> > that Geir looked into this as well. I found that it would be
> > quite easy to integrate Struts with Velocity and would not
> > require any changes to Struts. This would be a very attractive
> > combination of technologies for my work. It anyone else interested
> > in this as well?
> >
> > Gabe
> >
> > ---------------------
> > Eivycom
> > Technoparkstrasse 1
> > 8005 Zurich
> > Switzerland
> >
> > sidler@teamup.ch
> > +41 1 845 18 00
> > ---------------------

RE: semi-on-topic question

Posted by Paulo Gaspar <pa...@krankikom.de>.
But... is Struts really simple???
>;o)

Have fun,
Paulo

> -----Original Message-----
> From: jmcnally [mailto:jmcnally]On Behalf Of
> John McNally
> Sent: Tuesday, September 18, 2001 9:44 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: semi-on-topic question
> 
> 
> How have the developers on Struts reacted to talk of integrating
> Velocity as a view?  I thought a major reason for the formation of
> Struts was that Turbine allowed both jsp and velocity view layers and
> this was considered too complex and Struts was to be a single view
> technology only (jsp).
> 
> john mcnally
> 
> Gabriel Sidler wrote:
> > 
> > piero de salvia wrote:
> > >
> > > hi guys,
> > >
> > > i have a question that only marginally relates to
> > > Velocity, but it helps people that build sites with
> > > Velocity I think.
> > >
> > > what is the correct-truly-OO way of invoking methods
> > > [besides Turbine] in response to form submittals ?
> > >
> > > Is it reflection? That means form submits should be
> > > named after Java methods. this seems to me poor
> > > encapsulation, or brittle at least. Looking them up in
> > > a hash ? And even so, after you look it up, say you
> > > get a pointer to a class that has to do an if else
> > > chain, right? Poor OO again.
> > 
> > Apache Struts maps URLs to instances of so called action
> > classes. Action classes can be seen as request handlers or
> > request targets. Its the hastable approach.
> > Whether you have to use if-else-chains within the action
> > classes depends on how fine grained your action classes are.
> > I find its about finding a good compromise between the number
> > of action classes and some if-else chains.
> > For more complex applications, Struts offers an action class
> > that uses reflection to dispatch requests to methods, thereby
> > basically combining the hashtable approach with the reflection
> > approach.
> > 
> > One very useful feature of Struts in this context is that
> > one can define aliases for action classes. This introduces
> > an optional layer of indirection in the mapping of URLs to
> > action classes. I believe this would address some of your
> > concerns about poor encapsulation.
> > 
> > I am currently working on a Struts-based project and find it
> > a relatively simple and lightweight web app framework that
> > provides strong MVC concepts.
> > 
> > Unfortunately the view component of Struts is currently very
> > much JSP centric. However, I did spend some time a while ago
> > to look into integration of Velocity/WebMacro with Struts. I know
> > that Geir looked into this as well. I found that it would be
> > quite easy to integrate Struts with Velocity and would not
> > require any changes to Struts. This would be a very attractive
> > combination of technologies for my work. It anyone else interested
> > in this as well?
> > 
> > Gabe
> > 
> > ---------------------
> > Eivycom
> > Technoparkstrasse 1
> > 8005 Zurich
> > Switzerland
> > 
> > sidler@teamup.ch
> > +41 1 845 18 00
> > ---------------------
> 

Re: semi-on-topic question

Posted by John McNally <jm...@collab.net>.
How have the developers on Struts reacted to talk of integrating
Velocity as a view?  I thought a major reason for the formation of
Struts was that Turbine allowed both jsp and velocity view layers and
this was considered too complex and Struts was to be a single view
technology only (jsp).

john mcnally

Gabriel Sidler wrote:
> 
> piero de salvia wrote:
> >
> > hi guys,
> >
> > i have a question that only marginally relates to
> > Velocity, but it helps people that build sites with
> > Velocity I think.
> >
> > what is the correct-truly-OO way of invoking methods
> > [besides Turbine] in response to form submittals ?
> >
> > Is it reflection? That means form submits should be
> > named after Java methods. this seems to me poor
> > encapsulation, or brittle at least. Looking them up in
> > a hash ? And even so, after you look it up, say you
> > get a pointer to a class that has to do an if else
> > chain, right? Poor OO again.
> 
> Apache Struts maps URLs to instances of so called action
> classes. Action classes can be seen as request handlers or
> request targets. Its the hastable approach.
> Whether you have to use if-else-chains within the action
> classes depends on how fine grained your action classes are.
> I find its about finding a good compromise between the number
> of action classes and some if-else chains.
> For more complex applications, Struts offers an action class
> that uses reflection to dispatch requests to methods, thereby
> basically combining the hashtable approach with the reflection
> approach.
> 
> One very useful feature of Struts in this context is that
> one can define aliases for action classes. This introduces
> an optional layer of indirection in the mapping of URLs to
> action classes. I believe this would address some of your
> concerns about poor encapsulation.
> 
> I am currently working on a Struts-based project and find it
> a relatively simple and lightweight web app framework that
> provides strong MVC concepts.
> 
> Unfortunately the view component of Struts is currently very
> much JSP centric. However, I did spend some time a while ago
> to look into integration of Velocity/WebMacro with Struts. I know
> that Geir looked into this as well. I found that it would be
> quite easy to integrate Struts with Velocity and would not
> require any changes to Struts. This would be a very attractive
> combination of technologies for my work. It anyone else interested
> in this as well?
> 
> Gabe
> 
> ---------------------
> Eivycom
> Technoparkstrasse 1
> 8005 Zurich
> Switzerland
> 
> sidler@teamup.ch
> +41 1 845 18 00
> ---------------------

Re: semi-on-topic question

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 9/18/01 2:46 AM, "Gabriel Sidler" <si...@teamup.ch> wrote:

> piero de salvia wrote:
>> 
>> hi guys,
>> 
>> i have a question that only marginally relates to
>> Velocity, but it helps people that build sites with
>> Velocity I think.
>> 
>> what is the correct-truly-OO way of invoking methods
>> [besides Turbine] in response to form submittals ?
>> 
>> Is it reflection? That means form submits should be
>> named after Java methods. this seems to me poor
>> encapsulation, or brittle at least. Looking them up in
>> a hash ? And even so, after you look it up, say you
>> get a pointer to a class that has to do an if else
>> chain, right? Poor OO again.
> 
> Apache Struts maps URLs to instances of so called action
> classes. Action classes can be seen as request handlers or
> request targets. Its the hastable approach.
> Whether you have to use if-else-chains within the action
> classes depends on how fine grained your action classes are.
> I find its about finding a good compromise between the number
> of action classes and some if-else chains.
> For more complex applications, Struts offers an action class
> that uses reflection to dispatch requests to methods, thereby
> basically combining the hashtable approach with the reflection
> approach.
> 
> One very useful feature of Struts in this context is that
> one can define aliases for action classes. This introduces
> an optional layer of indirection in the mapping of URLs to
> action classes. I believe this would address some of your
> concerns about poor encapsulation.
> 
> I am currently working on a Struts-based project and find it
> a relatively simple and lightweight web app framework that
> provides strong MVC concepts.
> 
> Unfortunately the view component of Struts is currently very
> much JSP centric. However, I did spend some time a while ago
> to look into integration of Velocity/WebMacro with Struts. I know
> that Geir looked into this as well. I found that it would be
> quite easy to integrate Struts with Velocity and would not
> require any changes to Struts. This would be a very attractive
> combination of technologies for my work. It anyone else interested
> in this as well?

I think it would be great.  I did look into this a while ago and got things
working, and I know that there are others who have independently done the
same thing.

It seems perfectly possible to do this w/o any changes to the Struts core.
The challenges seem to be in accessing the basic tools/beans that struts
provides, such as the application error messages and such.

It sure would be fun to add this to our list of Velocity-supporting
frameworks :)

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
If you look up, there are no limits - Japanese Proverb


another semi-on-topic question

Posted by piero de salvia <pi...@yahoo.com>.
hi guys,

i hope not to stretch it too far with my off-topic
questions. feel free to ignore...

does anybody have a sample page that integrates the
micro$oft html visual controls? or does anybody know
an alternative to them ?

http://msdn.microsoft.com/workshop/author/dhtml/edit/default.asp

so i've managed to write an off-topic post about
micro$oft products...

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

Re: semi-on-topic question

Posted by Gabriel Sidler <si...@teamup.ch>.
piero de salvia wrote:
> 
> hi guys,
> 
> i have a question that only marginally relates to
> Velocity, but it helps people that build sites with
> Velocity I think.
> 
> what is the correct-truly-OO way of invoking methods
> [besides Turbine] in response to form submittals ?
> 
> Is it reflection? That means form submits should be
> named after Java methods. this seems to me poor
> encapsulation, or brittle at least. Looking them up in
> a hash ? And even so, after you look it up, say you
> get a pointer to a class that has to do an if else
> chain, right? Poor OO again.

Apache Struts maps URLs to instances of so called action
classes. Action classes can be seen as request handlers or
request targets. Its the hastable approach. 
Whether you have to use if-else-chains within the action 
classes depends on how fine grained your action classes are. 
I find its about finding a good compromise between the number 
of action classes and some if-else chains.
For more complex applications, Struts offers an action class 
that uses reflection to dispatch requests to methods, thereby
basically combining the hashtable approach with the reflection 
approach.

One very useful feature of Struts in this context is that
one can define aliases for action classes. This introduces
an optional layer of indirection in the mapping of URLs to
action classes. I believe this would address some of your 
concerns about poor encapsulation.

I am currently working on a Struts-based project and find it
a relatively simple and lightweight web app framework that
provides strong MVC concepts. 

Unfortunately the view component of Struts is currently very 
much JSP centric. However, I did spend some time a while ago
to look into integration of Velocity/WebMacro with Struts. I know
that Geir looked into this as well. I found that it would be
quite easy to integrate Struts with Velocity and would not 
require any changes to Struts. This would be a very attractive
combination of technologies for my work. It anyone else interested
in this as well?


Gabe


---------------------
Eivycom
Technoparkstrasse 1
8005 Zurich
Switzerland

sidler@teamup.ch
+41 1 845 18 00
---------------------

Re: semi-on-topic question

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 9/16/01 9:13 AM, "piero de salvia" <pi...@yahoo.com> wrote:

> hi guys,
> 
> i have a question that only marginally relates to
> Velocity, but it helps people that build sites with
> Velocity I think.
> 
> what is the correct-truly-OO way of invoking methods
> [besides Turbine] in response to form submittals ?
> 
> Is it reflection? That means form submits should be
> named after Java methods. this seems to me poor
> encapsulation, or brittle at least. Looking them up in
> a hash ? And even so, after you look it up, say you
> get a pointer to a class that has to do an if else
> chain, right? Poor OO again.
> 

In my little quickie stuff, I tend to have 'actions' that are just methods
in the servlet class, and they are looked up and invoked at runtime.

I have also done it by having the servlet introspect itself first, and then
cache those methods.

That's quicker.  I don't think its a huge deal, though...

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
If you look up, there are no limits - Japanese Proverb


Re: semi-on-topic question

Posted by Jon Stevens <jo...@latchkey.com>.
on 9/16/01 12:13 PM, "piero de salvia" <pi...@yahoo.com> wrote:

> hi guys,
> 
> i have a question that only marginally relates to
> Velocity, but it helps people that build sites with
> Velocity I think.
> 
> what is the correct-truly-OO way of invoking methods
> [besides Turbine] in response to form submittals ?
> 
> Is it reflection? That means form submits should be
> named after Java methods. this seems to me poor
> encapsulation, or brittle at least. Looking them up in
> a hash ? And even so, after you look it up, say you
> get a pointer to a class that has to do an if else
> chain, right? Poor OO again.
> 
> Some people in the list will wonder if I will ever
> learn Java programming....
> 
> yours affectionately,

Turbine uses something that I pulled out of my ass one day (but works quite
well): ActionEvents

Here is the documentation:

<http://jakarta.apache.org/turbine/turbine-2/howto/action-event-howto.html>

I don't think I could go back to using iftree's to find which button was
clicked. The other nice thing is that button names are now not tied to the
Java code.

Note: It does use reflection. It makes no perceivable speed hit because
Actions are not used all of the time and a single method lookup is not that
expensive in the grand scheme of things. We could add caching of the Method
that was looked up, but we haven't found a need to make things more complex
with very little benefit.

-jon


semi-on-topic question

Posted by piero de salvia <pi...@yahoo.com>.
hi guys,

i have a question that only marginally relates to
Velocity, but it helps people that build sites with
Velocity I think.

what is the correct-truly-OO way of invoking methods
[besides Turbine] in response to form submittals ?

Is it reflection? That means form submits should be
named after Java methods. this seems to me poor
encapsulation, or brittle at least. Looking them up in
a hash ? And even so, after you look it up, say you
get a pointer to a class that has to do an if else
chain, right? Poor OO again.

Some people in the list will wonder if I will ever
learn Java programming....

yours affectionately,

piero

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

Re: Escaping VTL elements

Posted by Peter Mutsaers <pe...@mutsaers.com>.
>> "Geir" == Geir Magnusson <ge...@optonline.net> writes:

    Geir> I don't think adding escaped chars would cause much havoc in
    Geir> 1.3 - we can have a deprecation mode flag to prevent it from
    Geir> breaking existing templates.  Something to consider.

That would be great and make macro's even more useful.

-- 
Peter Mutsaers  |  Dübendorf    | UNIX - Live free or die
plm@gmx.li      |  Switzerland  | Sent via FreeBSD 4.3-stable

Re: Escaping VTL elements

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 9/15/01 11:31 AM, "Peter Mutsaers" <pe...@mutsaers.com> wrote:

>>> "Geir" == Geir Magnusson <ge...@optonline.net> writes:
> 
>>> I've been considering to add a normal escaping mechanism
>>> myself, I can hardly imagine that this doesn't cause big grieve
>>> for "everyone".
> 
>   Geir> It seems not to.
> 
>   Geir> For example
> 
>   Geir>   #set($foo = ' This is my "string" ')
> 
>   Geir> Is perfectly legal VTL, and will be output as
> 
>   Geir>   This is my "string"
> 
> But what if you need to mix ", \n and context variables into one
> string? I started usage of velocity with heavy use of velocimacro, but
> not being able to easily giving strings with a mix of " (which you
> need a lot in html), \n and filling in context variables in
> macro-parameters caused quite a bit of pain, and forced me the ugly
> workaround of defining ${q} for ", ${nl} for newlines etc. etc.
> 
> The resulting templates didn't look nice, to say the least.
> 

Yep, agreed.  The VM's do give you the ability to package things up nicely
though - for example, putting together a nice set of VMs do to basic HTML
stuff, like a #link() macro...  I know Struts has a whole set of these as
tags...

I don't think adding escaped chars would cause much havoc in 1.3 - we can
have a deprecation mode flag to prevent it from breaking existing templates.
Something to consider.

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
If you look up, there are no limits - Japanese Proverb


Re: Escaping VTL elements

Posted by Peter Mutsaers <pe...@mutsaers.com>.
>> "Geir" == Geir Magnusson <ge...@optonline.net> writes:

    >> I've been considering to add a normal escaping mechanism
    >> myself, I can hardly imagine that this doesn't cause big grieve
    >> for "everyone".

    Geir> It seems not to.

    Geir> For example

    Geir>   #set($foo = ' This is my "string" ')

    Geir> Is perfectly legal VTL, and will be output as

    Geir>   This is my "string"

But what if you need to mix ", \n and context variables into one
string? I started usage of velocity with heavy use of velocimacro, but
not being able to easily giving strings with a mix of " (which you
need a lot in html), \n and filling in context variables in
macro-parameters caused quite a bit of pain, and forced me the ugly
workaround of defining ${q} for ", ${nl} for newlines etc. etc.

The resulting templates didn't look nice, to say the least.


-- 
Peter Mutsaers  |  Dübendorf    | UNIX - Live free or die
plm@gmx.li      |  Switzerland  | Sent via FreeBSD 4.3-stable

Re: Escaping VTL elements

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 9/14/01 8:48 PM, "Peter Mutsaers" <pe...@mutsaers.com> wrote:

>>> "Stuart" == Stuart Churchill <SC...@caluk.com> writes:
> 
>   Stuart> Secondly, an escaping problem that I've not yet found a
>   Stuart> workaround for. My destination template should contain a
>   Stuart> reference '$!BreederSurname'. My source template includes
>   Stuart> a reference '$column.getName()', which in this instance
>   Stuart> returns the value "BreederSurname". How do I combine the
>   Stuart> two ?
> 
> The lack of normal \-style escaping has been a great source of
> annoyance for me too.

There is \-style escaping for references and directives.

See the Users' Guide.

I assume you mean in strings.  We don't have \-style escaping of \n, ", ' in
VTL strings, but we can drop that into 1.3.

> 
> I've used some addition to the context, such as $q being predefined as ".
> 
> But that is an ugly hack of course, and looks horrible on template
> pages with lots of macro's etc (where all parameters containing
> characters like " have to be escaped, and you can't use '...' because
> the parameter may contain context variables too.
> 
> I've been considering to add a normal escaping mechanism myself, I can
> hardly imagine that this doesn't cause big grieve for "everyone".

It seems not to.

For example

  #set($foo = ' This is my "string" ')

Is perfectly legal VTL, and will be output as

  This is my "string"

 
> Instead I must say I have stopped using velocity (moved back to JSP,
> but now strictly as a template mechanism under control of a
> servlet-controller).

That's too bad.

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
If you look up, there are no limits - Japanese Proverb


Re: Escaping VTL elements

Posted by Peter Mutsaers <pe...@mutsaers.com>.
>> "Stuart" == Stuart Churchill <SC...@caluk.com> writes:

    Stuart> Secondly, an escaping problem that I've not yet found a
    Stuart> workaround for. My destination template should contain a
    Stuart> reference '$!BreederSurname'. My source template includes
    Stuart> a reference '$column.getName()', which in this instance
    Stuart> returns the value "BreederSurname". How do I combine the
    Stuart> two ?

The lack of normal \-style escaping has been a great source of
annoyance for me too.

I've used some addition to the context, such as $q being predefined as ".

But that is an ugly hack of course, and looks horrible on template
pages with lots of macro's etc (where all parameters containing
characters like " have to be escaped, and you can't use '...' because
the parameter may contain context variables too.

I've been considering to add a normal escaping mechanism myself, I can
hardly imagine that this doesn't cause big grieve for "everyone".

Instead I must say I have stopped using velocity (moved back to JSP,
but now strictly as a template mechanism under control of a
servlet-controller).

-- 
Peter Mutsaers  |  Dübendorf    | UNIX - Live free or die
plm@gmx.li      |  Switzerland  | Sent via FreeBSD 4.3-stable

Re: Escaping VTL elements

Posted by Jason van Zyl <jv...@apache.org>.
On 9/12/01 10:49 AM, "Jon Stevens" <jo...@latchkey.com> wrote:

> on 9/12/01 7:04 AM, "Jason van Zyl" <jv...@apache.org> wrote:
> 
>> You can use
>> 
>> #literal
>> 
>> <valid VTL>
>> 
>> #end
> 
> ?

It's been in there for a long time, but I meant to make it cleaner than geir
wanted to make it cleaner but neither of us ever got around to it, but it
exists.
 
> -jon

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



Re: Escaping VTL elements

Posted by Jon Stevens <jo...@latchkey.com>.
on 9/12/01 7:04 AM, "Jason van Zyl" <jv...@apache.org> wrote:

> You can use
> 
> #literal
> 
> <valid VTL>
> 
> #end

?

-jon


RE: Escaping VTL elements

Posted by Will Glass-Husain <wg...@forio.com>.
I've struggled with this too.  When I asked a similar (not quite identical)
question a while back, Jon pointed out that it you put the ## in single
quotes, you can use it in the page.

"##" gives an error
'##' is okay.

WILL

-----Original Message-----
From: Jason van Zyl [mailto:jvanzyl@apache.org]
Sent: Wednesday, September 12, 2001 7:04 AM
To: velocity-user@jakarta.apache.org
Subject: Re: Escaping VTL elements


On 9/12/01 9:35 AM, "Stuart Churchill" <SC...@caluk.com> wrote:

>
> Hi folks,
>
> I'm using Velocity to generate Java classes, servlets and other templates,
> based upon a given database schema. Up to now, everything was tickety-boo,
> but I'm having some problems writing templates that get parsed to produce
> other templates.
>
> The first problem was how to escape a comment directive ('##') in my
source
> template, so that it would be written out correctly to my destination
> template. At the moment, the undernoted code works, but is there another
way
> ?
>
> #set ($hash = "#")
> $hash$hash
> $hash$hash This is a comment to appear in the output
> $hash$hash

You can use

#literal

<valid VTL>

#end


> Secondly, an escaping problem that I've not yet found a workaround for. My
> destination template should contain a reference '$!BreederSurname'. My
> source template includes a reference '$column.getName()', which in this
> instance returns the value "BreederSurname". How do I combine the two ?
>
> I've trawled the documentation, and the archives, but the closest I could
> find was a message from Geir in December last year, ("more escaping fun"),
> which touched on the issue, but didn't solve it for me.
>
>  Cheers,
>
>      Stu.
>
>  Lead Developer  -  Computer Applications Ltd
>

--

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



Re: Escaping VTL elements

Posted by Jason van Zyl <jv...@apache.org>.
On 9/12/01 9:35 AM, "Stuart Churchill" <SC...@caluk.com> wrote:

> 
> Hi folks,
> 
> I'm using Velocity to generate Java classes, servlets and other templates,
> based upon a given database schema. Up to now, everything was tickety-boo,
> but I'm having some problems writing templates that get parsed to produce
> other templates.
> 
> The first problem was how to escape a comment directive ('##') in my source
> template, so that it would be written out correctly to my destination
> template. At the moment, the undernoted code works, but is there another way
> ?
> 
> #set ($hash = "#")
> $hash$hash
> $hash$hash This is a comment to appear in the output
> $hash$hash

You can use

#literal

<valid VTL>

#end

 
> Secondly, an escaping problem that I've not yet found a workaround for. My
> destination template should contain a reference '$!BreederSurname'. My
> source template includes a reference '$column.getName()', which in this
> instance returns the value "BreederSurname". How do I combine the two ?
> 
> I've trawled the documentation, and the archives, but the closest I could
> find was a message from Geir in December last year, ("more escaping fun"),
> which touched on the issue, but didn't solve it for me.
> 
>  Cheers,
> 
>      Stu.
> 
>  Lead Developer  -  Computer Applications Ltd
> 

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



Re: Escaping VTL elements

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 9/12/01 3:35 AM, "Stuart Churchill" <SC...@caluk.com> wrote:

> 
> Hi folks,
> 
> I'm using Velocity to generate Java classes, servlets and other templates,
> based upon a given database schema. Up to now, everything was tickety-boo,
> but I'm having some problems writing templates that get parsed to produce
> other templates.
> 
> The first problem was how to escape a comment directive ('##') in my source
> template, so that it would be written out correctly to my destination
> template. At the moment, the undernoted code works, but is there another way
> ?
> 
> #set ($hash = "#")
> $hash$hash
> $hash$hash This is a comment to appear in the output
> $hash$hash

You've seen the other comments re #literal

Personally, I would love to see that disappear, but that's another story...

The trick here is to use

#set($hash = '#')

So it doesn't get parsed.  The double quote " means that it's parsed.

Then it should work fine.

> 
> Secondly, an escaping problem that I've not yet found a workaround for. My
> destination template should contain a reference '$!BreederSurname'. My
> source template includes a reference '$column.getName()', which in this
> instance returns the value "BreederSurname". How do I combine the two ?

Same thing - use a non-parsed string :

#set($thingy = '$column.getName()')

You need to do this in the context of a directive (like #set ) to ensure
that Velocity takes it as a string.  Otherwise, if not in a directive, then
the ' is simply schmoo (non-VTL content) and and will render literally as a
'.

Hope that's clear.
 
> I've trawled the documentation, and the archives, but the closest I could
> find was a message from Geir in December last year, ("more escaping fun"),
> which touched on the issue, but didn't solve it for me.

See if that solves it.

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
If you look up, there are no limits - Japanese Proverb