Add Values to a Sequence?
You have to create a new sequence by concatenating x and a sequence containing only the new element: <#assign x = x + [ “green” ] />
You have to create a new sequence by concatenating x and a sequence containing only the new element: <#assign x = x + [ “green” ] />
I designed ST to build jGuru after getting sick of the “code in template” model of JSP. Velocity and friends (i.e., every other engine i think) give you more power than you need. I used basically four features to build jGuru.com (as described in paper). More features are unnecessary and lead you to entangle your … Read more
It’s actually not really clearly stated in the standard (RFC 3986) whether a percent-encoded version of . or .. is supposed to have the same this-folder/up-a-folder meaning as the unescaped version. Section 3.3 only talks about “The path segments . and ..”, without clarifying whether they match . and .. before or after pct-encoding. Personally … Read more
Try: <#if node.attachments?size != 0> Or: <#if node.attachments?has_content>
this is what ended up working for me: freemarkerConfiguration = new Configuration(Configuration.VERSION_2_3_28); freemarkerConfiguration.setClassForTemplateLoading(this.getClass(), “https://stackoverflow.com/”); Template freemarkerTemplate = freemarkerConfiguration.getTemplate(“email/vendor.tpl”);
Use the has_content built-in: <#if list5?has_content>
The root of the classpath is src/main/resources, change the path to configuration.setClassForTemplateLoading(this.getClass(), “/templates/”);
This should print ${person.name}: ${r”${person.name}”} From the freemarker docs A special kind of string literals is the raw string literals. In raw string literals, backslash and ${ have no special meaning, they are considered as plain characters. To indicate that a string literal is a raw string literal, you have to put an r directly … Read more
Is “jobs” really a collection? Please post a snippet of code where you are creating and processing your template. I just wrote a quick test to check: public void testFreeMarker() throws Exception { List<Invoice> invoices = Arrays.asList( new Invoice( “note1”, “amount1” ), new Invoice( “note2”, “amount2” ) ); Map<String, Object> root = new HashMap<String, Object>(); … Read more
The javadoc is quite explicit: Closing a StringWriter has no effect. And a quick look at the code confirms it: public void close() throws IOException { }