0

In summary, I need to find a way to use value from .properties files in a Thymeleaf template.

In details now, I want to have Google Analytics on my page. There are development and production application build profiles. Each of these profiles has its directory with properties. The account details are in these properties files.

For now I assign the appropriate values to variables in the model and use them.

<script type="text/javascript" th:inline="javascript">
    var _gaq = _gaq || [];
    var _gaId = /*[[${googleAnalyticsId}]]*/'';//these are the variables I'm talking about
    var _gaDomainName = /*[[${googleAnalyticsDomainName}]]*/'';
    _gaq.push(['_setAccount', _gaId]);
    _gaq.push(['_setDomainName', _gaDomainName]);
    _gaq.push(['_trackPageview']);
</script>

But it seems quite dirty, let alone the manoeuvring that needs to be done in order to change any of these values.

What I'd like to do in the page template is to just point to the property name like we do in Spring with @Value. E.g.

<script type="text/javascript" th:inline="javascript">
    var _gaq = _gaq || [];
    var _gaId = /*[[${google.analytics.id}]]*/'';//I want to assign values directly from the properties file
    var _gaDomainName = /*[[${google.analytics.domain.name}]]*/'';
    _gaq.push(['_setAccount', _gaId]);
    _gaq.push(['_setDomainName', _gaDomainName]);
    _gaq.push(['_trackPageview']);
</script>

Thanks in advance.

4

1 回答 1

0

为什么你不能使用标准的消息源方式#{googleAnalyticsDomainName}

于 2013-10-18T16:22:10.753 回答