I have Apache Velocity.
I have some jQuery code.
I think VM doesn t like when I do things like $img.css("float","left")
.
How can I completely disable VM parsing within a block of HTML/Javascript ?
Thanks
I have Apache Velocity.
I have some jQuery code.
I think VM doesn t like when I do things like $img.css("float","left")
.
How can I completely disable VM parsing within a block of HTML/Javascript ?
Thanks
For short examples, like the above, if it isn t a legitimate Velocity reference, just do $img and Velocity will ignore it.
It s tempting to escape the reference, but this is extremely quirky. If $img is a real reference, then $img will display $img. But if $img is not a Velocity reference, then $img will display $img.
The best bet, especially if you have a long block of text you do not want parsed, is to put it in a separate file and use #include, which does not parse the include text.
#include("file.vm")
This will include "file.vm" directly into the output without parsing it. (If you want to include text and parse that text, use #parse).
Velocity 1.7-beta1 is now out, and it ships the #[[don t parse me!]]#
directive, so you don t have to escape a bunch of code in your .vm files.
Works for me like a charm.
Looking at the user guide it looks like as long as you don t have a variable named $img
in velocity, you shouldn t have a problem with velocity parsing it. Otherwise you can escape with $img
.
As far as actually having the parser skip over the the string as you would with a CDATA tag in XML, I m not sure how you could do that.
The escaping is unreliable. Do:
context.put("D", "$");
and then
${D}img
In the upcoming 1.7, there is a new #[[ parser will ignore this completely ]]# syntax. Hopefully a 1.7-beta1 will be out soon.
You can escape the dollar sign in Velocity by preceding each $ sign with a backslash...
$img.css("float", "left");
You can assign a variable to parse the dollar sign. For example:
#set( $jQ = "$" )
Now you can use this variable to place a dollar sign where you need to:
<script type="text/javascript">
$jQ img.css();
</script>
Please ensure there s a space between the $jQ variable and the img.css(); (so that velocity doesn t try to interpret the rest as a different variable). You won t have to do this if a parenthesis follows directly after the $jQ var.
This would be fine:
$jQ( #smithySword );
The $
in jquery is a shorthand for jQuery
, therefore you can substitute any $
with jQuery
I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...
I would like to know the size of the movie I am watching on any video site [ if not possible on all video sites, then at least on YouTube ]. So is it possible, say I will specify the complete path ...
Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...
I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...
The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...
I can easily do this with JQuery or PHP but I have a project for my Intro to C++ class and I thought it ll be pretty cool if I could mix C++ with some APIs like twitter, google, yahoo etc. Could you ...
I have never dealt with regular expressions before, and I am facing a problem here. The user has to input a text like Var1(0,enum1,enum2), and I have to check the syntax on the following manner:- 1- ...
I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...