Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FreeMarker ?replace multiple values

Is it possible to replace multiple values in a FreeMarker template? For example, if I want to replace "a" and "b" with "c", I have to do this:

${event.EventTitle?replace('a','c')?replace('b','c')}

but I'd rather do something like this:

${event.EventTitle?replace("'a','b'",'c')}

Any chance FreeMarker has this capability?

I'm ultimately trying to replace all special characters ($,.,@,&,etc) with dashes, so feel free to suggest an easier way to do that.

like image 473
Ali Torbati Avatar asked Jul 09 '13 00:07

Ali Torbati


People also ask

How do Freemarkers multiply?

Arithmetical calculations So the operators are: Addition: + Subtraction: - Multiplication: *

How do you escape characters in FreeMarker?

esc creates a markup output value out of a string value by escaping all special characters in it.

Is FreeMarker case sensitive?

The string converted to boolean value. The string must be true or false (case sensitive!), or must be in the format specified by the boolean_format setting. If the string is not in the appropriate format, an error will abort template processing when you try to access this built-in.

Does FreeMarker have content?

The has_content FunctionFreeMarker has built-in functions to detect for variables. The most common method of detecting for empty or null values uses the has_content function and the trim function. The has_content function is often used with another built-in FreeMarker function to detect for null values.


1 Answers

You could use a regular expression for this:

${event.EnventTitle?replace('a|b', 'c', 'r')}

Note the 'r' at the end.

like image 166
ddekany Avatar answered Sep 18 '22 07:09

ddekany