velocity

Access velocity variable with javascript

余生长醉 提交于 2019-12-22 05:46:14
问题 <head> #set($test = "works")) </head> <script> var get = "${test}"; // I also tried using '$test' and "$test" also alert(get); </script> And it alerts out ${test} , but should print works . How can I get it to work? 回答1: try this... #set ($test = "works") <script type="text/javascript"> var myvar = "${test}"; alert (myvar); </script> THIS WORKS SURELY!!!! 回答2: Try var get = "$test"; instead of var get = "${test}"; 回答3: I realize the question is old, but this worked for me: #set ($test = "hi")

Create object in velocity template

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 03:58:10
问题 I am writing velocity templates for my liferay theme and I am wondering, whether it is possible to create a new object inside the velocity template. The reason is that in liferay there is no contextTool registered in the context and I really want to be able to inspect the variables that are present in the template at a given time. There is a cool macro for this, but unfortunately it uses the contexttool. I'd like to do something like: #set($contextTool = new ContextTool()) Another solution

Create object in velocity template

倖福魔咒の 提交于 2019-12-22 03:56:05
问题 I am writing velocity templates for my liferay theme and I am wondering, whether it is possible to create a new object inside the velocity template. The reason is that in liferay there is no contextTool registered in the context and I really want to be able to inspect the variables that are present in the template at a given time. There is a cool macro for this, but unfortunately it uses the contexttool. I'd like to do something like: #set($contextTool = new ContextTool()) Another solution

How to select the format of $date in vm file?

元气小坏坏 提交于 2019-12-22 03:42:32
问题 I have a $date defined as "day of week, month day, year" ex: Tuesday, February 26, 2013 I don't know where $date is defined but I like to add the hour to this $date variable, or create a variable with the hour, do you know how can I put it in the .vm file? 回答1: Velocity provides a DateTool class for formatting dates. You would need to put an instance of this class into your velocity context: context.add("date", new DateTool()); Then you could use a formatting command like: $date.format('EEE,

Velocity templates seem to fail with UTF-8

左心房为你撑大大i 提交于 2019-12-22 02:21:49
问题 I have been trying to use a velocity Template with the following content: Sübjäct $item Everything works fine except the translation of the two Unicode characters. The result string printed on the command line looks like: Sübjäct foo I searched the velocity website and the web for this issue, and came up with different font encoding options, which I added to my code. But these don't help. This is the actual code: velocity.setProperty("file.resource.loader.path", absPath); velocity

Defining database queries inside Velocity templates

北城余情 提交于 2019-12-21 17:39:33
问题 I am looking at various libraries that can be used as a templating engine in my project and right now Apache Velocity looks like a good candidate. I have the following doubts regarding its usage: Is it possible to specify a SQL database query in a template and use the querys' return value to fill a parameter?. I found the following example in the Velocity user guide: Hello, #set( $result = $query.criteria("name") ) Your username is $result. However the guide does not explain much about

IntelliJ IDEA override $user

一笑奈何 提交于 2019-12-21 04:49:15
问题 It's a quite simple question, but I can't find an answer to it using SO-Search and Google. Is it possible to override the default $user VTL-variable used in file-templates globally, instead of setting it in each template with #set($user = "...") ? Like some sort of setup-script for IntelliJ itself, where I can alter the value? Thanks in advance. By the way, I'm using IntelliJ Ultimate 12.1.6. 回答1: You want to modify the IntelliJ's .vmoptions file(s) in a text editor. In Windows, edit IntelliJ

What is the best way to access an array inside Velocity?

扶醉桌前 提交于 2019-12-20 16:54:09
问题 I have a Java array such as: String[] arr = new String[] {"123","doc","projectReport.doc"}; In my opinion the natural way to access would be: #set($att_id = $arr[0]) #set($att_type = $arr[1]) #set($att_name = $arr[2]) But that it is not working. I have come with this workaround. But it a bit too much code for such an easy task. #set($counter = 0) #foreach($el in $arr) #if($counter==0) #set($att_id = $el) #elseif($counter==1) #set($att_type = $el) #elseif($counter==2) #set($att_name = $el)

How to #include a file from a Velocity template using ClasspathResourceLoader

落花浮王杯 提交于 2019-12-20 12:24:47
问题 I'm dealing with some Java code where Velocity 1.7 is set to retrieve templates through the ClasspathResourceLoader. Below is a stripped down sample of the code. It's from a Tapestry web application running on a Jetty server. The Java class, the templates and the file to be included are all are in the same folder "testpackage", so in the resulting JAR they are all in the same package "testpackage". The problem is that if the template contains an #include("MyInclude.vm") directive, Velocity

How can I provide custom logic in a Maven archetype?

送分小仙女□ 提交于 2019-12-20 10:37:07
问题 I'm interested in creating a Maven archetype, and I think I have most of the basics down. However, one thing I'm stuck on is that sometimes I want to use custom logic to fill in a template. For example, if somebody generates my archetype and specifies the artifactId as hello-world, I'd like to generate a class named HelloWorld that simply prints out "Hello World!" to the console. If another person generates it with artifactId = howdy-there, the genned class would be HowdyThere and it would