You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Henning P. Schmiedehausen" <ma...@hometree.net> on 2001/06/01 15:31:14 UTC
Dumb question
Hi,
probably a really dumb question, but how can you do this:
#set ($myP = "<P CLASS="foo">$message</P>" )
^ ^
! !
using #set ($myP = '<P CLASS="foo">$message</P>' )
does not evaluate my variable
using #set ($myP = "<P CLASS=\"foo\">$message</P>" )
puts \"foo\" into the HTML page
and using #set ($myP = "<P CLASS=""foo"">$message</P>" )
simply is a syntax error.
I didn't find anything in the docs about escaping characters.
Regards
Henning
--
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH hps@intermeta.de
Am Schwabachgrund 22 Fon.: 09131 / 50654-0 info@intermeta.de
D-91054 Buckenhof Fax.: 09131 / 50654-20
Re: Dumb question
Posted by Christoph Reck <Ch...@dlr.de>.
One way of doing this is:
#set( $Q = '"' )
#set( $myP = "<P CLASS=${Q}foo${Q}>$message</P>" )
You can also achieve the same by splitting up the directive:
#set( $myP = '<P CLASS="foo">' )
#set( $myP = "$myP$message</P>" )
Note that this looks ugly because you are doing a
set with an embedded string. If you were just outputting
text, things would be straightforward:
<P CLASS="foo">$message</P>
Hope this helped.
:) Chirstoph
"Henning P. Schmiedehausen" wrote:
>
> Hi,
>
> probably a really dumb question, but how can you do this:
>
> #set ($myP = "<P CLASS="foo">$message</P>" )
> ^ ^
> ! !
>
> using #set ($myP = '<P CLASS="foo">$message</P>' )
> does not evaluate my variable
>
> using #set ($myP = "<P CLASS=\"foo\">$message</P>" )
> puts \"foo\" into the HTML page
>
> and using #set ($myP = "<P CLASS=""foo"">$message</P>" )
> simply is a syntax error.
>
> I didn't find anything in the docs about escaping characters.
>
> Regards
> Henning
>
> --
> Dipl.-Inf. (Univ.) Henning P. Schmiedehausen -- Geschaeftsfuehrer
> INTERMETA - Gesellschaft fuer Mehrwertdienste mbH hps@intermeta.de
>
> Am Schwabachgrund 22 Fon.: 09131 / 50654-0 info@intermeta.de
> D-91054 Buckenhof Fax.: 09131 / 50654-20
Re: Dumb question
Posted by Jon Stevens <jo...@latchkey.com>.
on 6/2/01 4:16 AM, "Henning P. Schmiedehausen" <ma...@hometree.net>
wrote:
> Jon Stevens <jo...@latchkey.com> writes:
>
>> This is a bad design. You are embedding HTML within "code".
>
> You neither know, _why_ I try to do this nor do you have enough
> context to judge on the designs of me or other developers.
I'm judging your use of Velocity by the example that you gave. That is all I
have. So, given that fact, I maintain that the example you gave is bad
design. :-)
> My whole code looks like this:
>
> [...]
> #if (!$key.isValid())
> #set($_error = "<P CLASS='error'>$key.Message</P>" )
> #end
> <TD>${message}${_error}</TD>
> [...]
>
> So I want to get either
>
> <TD>this is my message</TD>
>
> or
>
> <TD>This is my message<P CLASS="error">But it contains an error</P></TD>
You may want to put a space between ${message}${_error} because otherwise,
on the screen, the text will look stuck together.
> I'm very aware that I can write this like
>
> [...]
> <TD>${message}#if (!$key.isValid())<P CLASS="error">$key.Message</P>"#end</TD>
> [...]
>
> But please tell me, which one is less readable.
<TD>
${message}
#if (!$key.isValid())
<P CLASS="error">$key.Message</P>
#end
</TD>
Insert a few carriage returns and it seems perfectly readable to me and also
"fixes" the missing space error I mentioned above. Also note, I removed an
extra " that you left in there by accident.
> and this one:
> [...]
> <TD>${message}
> #if (!$key.isValid())
> <P CLASS="error">$key.Message</P>"
> #end
> </TD>
> [...]
>
> produces
>
> <TD>this is my message</TD>
>
> or
>
> <TD>This is my message
> <P CLASS="error">But it contains an error</P>
> </TD>
In HTML there is no problem with the extra returns. Also, you may want to
use XHTML instead of HTML since that is quickly becoming more of a standard
and you may want to process your documents with an XML parser someday in the
future. Might as well save the future headaches now.
>> If you want to re-use that:
>
>> #macro (pfoo $message)<p class="foo">$message</p>#end
>
>> #pfoo("here we are")
>
> This is the good solution. I will use that. Thanks.
>
> Regards
> Henning
I'm glad we agree on something. :-)
-jon
--
"Open source is not available to commercial companies."
-Steve Balmer, CEO Microsoft
<http://www.suntimes.com/output/tech/cst-fin-micro01.html>
Re: Dumb question
Posted by "Henning P. Schmiedehausen" <ma...@hometree.net>.
Jon Stevens <jo...@latchkey.com> writes:
>This is a bad design. You are embedding HTML within "code".
You neither know, _why_ I try to do this nor do you have enough
context to judge on the designs of me or other developers.
My whole code looks like this:
[...]
#if (!$key.isValid())
#set($_error = "<P CLASS='error'>$key.Message</P>" )
#end
<TD>${message}${_error}</TD>
[...]
So I want to get either
<TD>this is my message</TD>
or
<TD>This is my message<P CLASS="error">But it contains an error</P></TD>
I'm very aware that I can write this like
[...]
<TD>${message}#if (!$key.isValid())<P CLASS="error">$key.Message</P>"#end</TD>
[...]
But please tell me, which one is less readable.
and this one:
[...]
<TD>${message}
#if (!$key.isValid())
<P CLASS="error">$key.Message</P>"
#end
</TD>
[...]
produces
<TD>this is my message</TD>
or
<TD>This is my message
<P CLASS="error">But it contains an error</P>
</TD>
>If you want to re-use that:
>#macro (pfoo $message)<p class="foo">$message</p>#end
>#pfoo("here we are")
This is the good solution. I will use that. Thanks.
Regards
Henning
--
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH hps@intermeta.de
Am Schwabachgrund 22 Fon.: 09131 / 50654-0 info@intermeta.de
D-91054 Buckenhof Fax.: 09131 / 50654-20
Re: Dumb question
Posted by Jon Stevens <jo...@latchkey.com>.
on 6/1/01 6:31 AM, "Henning P. Schmiedehausen" <ma...@hometree.net>
wrote:
> Hi,
>
> probably a really dumb question, but how can you do this:
>
> #set ($myP = "<P CLASS="foo">$message</P>" )
> ^ ^
> ! !
>
> using #set ($myP = '<P CLASS="foo">$message</P>' )
> does not evaluate my variable
>
> using #set ($myP = "<P CLASS=\"foo\">$message</P>" )
> puts \"foo\" into the HTML page
>
> and using #set ($myP = "<P CLASS=""foo"">$message</P>" )
> simply is a syntax error.
>
> I didn't find anything in the docs about escaping characters.
>
> Regards
> Henning
This is a bad design. You are embedding HTML within "code".
<p class="foo">$message</p>
If you want to re-use that:
#macro (pfoo $message)<p class="foo">$message</p>#end
#pfoo("here we are")
Output:
<p class="foo">here we are</p>
-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>