I am trying to print accented characters with Freemarker, but in the place of accented characters, I get only question marks. I have verified, that following statement holds:
"UTF-8" == Environment.getCurrentEnvironment().getConfiguration().getDefaultEncoding()
I can easily see, that the accented characters are correctly held in the variable before giving it to the template.
My freemarker context can be found here: https://gist.github.com/1975239
For instance instead of:
Jedinečný živý koncert, kde nejen, že uslyšíte, ale i uvidíte splynutí metalové kapely s padesátičlenným orchestrem včetně.
I keep getting:
Jedine?ný ?ivý koncert, kde nejen, ?e usly?íte, ale i uvidíte splynutí metalové kapely s padesáti?lenným orchestrem v?etn?.
Thanks.
esc creates a markup output value out of a string value by escaping all special characters in it.
eval. This built-in evaluates a string as an FTL expression. For example "1+2"? eval returns the number 3. (To render a template that's stored in a string, use the interpret built-in instead.)
Comments: Comments are similar to HTML comments, but they are delimited by <#-- and --> . Comments will be ignored by FreeMarker, and will not be written to the output.
For example, if you create a variable called "foo" in the template, you can print its value with ${foo} . If, coincidently, there's a variable called "foo" in the data-model too, the variable created in the template will hide (not overwrite!)
For DROPWIZARD Users: passing through the UTF-8 Charset in the constructor worked out:
import io.dropwizard.views.View;
import java.nio.charset.Charset;
public class SomeView extends View {
public SomeView() {
super("/views/some.ftl", Charset.forName("UTF-8"));
}
}
I was able to resolve a similar issue with non-standard symbols (like ™) by setting the content-type on the FreeMarkerViewResolver:
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
...
<property name="contentType" value="text/html;charset=UTF-8"/>
...
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With