I started using Freemarker for assembling simple HTML pages, using FMPP Maven plugin. So far so good. But one thing I need to do is to include value of a system property (one of system properties Maven provides) on a page. Is there a way to access system properties from Freemarker templates? (if not, I may just have to hack plugin to allow passing values from Maven)
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
cf https://community.jivesoftware.com/thread/14820
You can access it like this :
cf documentation here : http://freemarker.sourceforge.net/docs/pgui_misc_beanwrapper.html
FMPP has a setting called
data
that specifies the variables that all templates will see, so that's where you should put the system properties. To put values into there, unless the value can be specified as a simple literal, you need a so called data-loader. So in this case you need a data-loader that returns the system properties as ajava.util.Properties
object. While there's no data-loader specifically for that, you can use theeval
data-loader like this (in yourconfig.fmpp
):Now in your templates you can access the system properties like
sysProps["os.name"]
.Alternatively, you could write a custom FMPP data-loader. See http://fmpp.sourceforge.net/dataloader.html#sect19.