Discussion:
Hyphen causing error in Velocity template
forums-YrDk4eUcT3KaMJb+
2011-05-23 17:41:13 UTC
Permalink
I have a Velocity template that is copied from the Comment section from an Issue. I want to put an internal page link, down to a specific Comment ID.

However, when I attempt to put a variable ($commentId) in the href link, I keep getting a Velocity error, complaining about the hyphen. I've tried using character codes for the hyphen, that didn't work either.

I'm stuck with the hyphen, because that's how Atlassian has decided to name the id's for the Comments section. I've tried searching on using a hyphen in Velocity scripts, and found some reference that it needs to be handled differently, but can't find the answer.

If I don't put a velocity $variable in the href statement, it works just fine. I think the hash (#) in front of comment is what's setting the whole thing off. if I remove the #, it also works ok, with the variable.

Here's the line from my Velocity script:
{code}
<a href="${urlPrefix}#comment-$commentId-open"><font size="1" color="grey">...(truncated)</font></a>
{code}

Here's the error I get:
{code}
org.apache.velocity.exception.ParseErrorException: Lexical error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 18, column 47. Encountered: "-" (45)
{code}

Thanks for any help.

-Cory
--
Post by csytsma - online at:
http://forums.atlassian.com/thread.jspa?forumID=100&threadID=54146
forums-YrDk4eUcT3KaMJb+
2011-05-23 20:53:51 UTC
Permalink
Hash (#) is velocity for "the next string is a velocity command"

You need to escape the # - I've not tried it, but I seem to remember \ should do it
{code}
<a href="${urlPrefix}\#comment-$commentId-open">
{code}
--
Post by broughn2 - online at:
http://forums.atlassian.com/thread.jspa?forumID=100&threadID=54146
forums-YrDk4eUcT3KaMJb+
2011-05-24 15:28:22 UTC
Permalink
Thanks Nic, that did it. I tried escaping everything else, but never tried the hash.

Just before seeing your post, I did put the hash in a variable, and that worked. But the backslash is much simpler.

-Cory
--
Post by csytsma - online at:
http://forums.atlassian.com/thread.jspa?forumID=100&threadID=54146
Loading...