# Accessing static fields in freemarker templates

**URL:** <https://community.bloomreach.com/t/accessing-static-fields-in-freemarker-templates/354>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [September 3, 2018, 10:12am UTC](https://community.bloomreach.com/t/accessing-static-fields-in-freemarker-templates/354 "2018-09-03T10:12:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mriegler](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/mriegler/32/178_2.png) [@mriegler](https://community.bloomreach.com/u/mriegler)\
**Post date:** [September 3, 2018, 10:12am UTC](https://community.bloomreach.com/t/accessing-static-fields-in-freemarker-templates/354/1 "2018-09-03T10:12:02Z")

</div>

I want to access static fields in my freemarker. Specifically, those of the Calendar class so i can display Dates the way i want.

According to Google ([https://stackoverflow.com/questions/9659547/freemarker-access-static-variables-of-an-object](https://stackoverflow.com/questions/9659547/freemarker-access-static-variables-of-an-object)) i would need to modify how the Data that Freemarker is called with is created, but from a cursory search of the Hippo Code, i couldn’t find a class to change/override.

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_der\_Vors](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Martijn\_van\_der\_Vors](https://community.bloomreach.com/u/Martijn_van_der_Vors)\
**Post date:** [September 3, 2018, 10:43am UTC](https://community.bloomreach.com/t/accessing-static-fields-in-freemarker-templates/354/2 "2018-09-03T10:43:11Z")

</div>

You could try adding the Object/Class to the request in your component’s doBeforeRender. That way you can access it in your freemarker template.

However for displaying dates in different ways, I would suggest using Freemarker’s built in capabilities:  
[https://freemarker.apache.org/docs/ref\_builtins\_date.html](https://freemarker.apache.org/docs/ref_builtins_date.html)

---

<div class="post-metadata">

**Author:** ![bcanvural](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/bcanvural/32/235_2.png) [@bcanvural](https://community.bloomreach.com/u/bcanvural)\
**Post date:** [September 3, 2018, 10:54am UTC](https://community.bloomreach.com/t/accessing-static-fields-in-freemarker-templates/354/3 "2018-09-03T10:54:33Z")

</div>

In addition to above, you can also add methods to your beans and access them in freemarker

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [September 3, 2018, 11:30am UTC](https://community.bloomreach.com/t/accessing-static-fields-in-freemarker-templates/354/4 "2018-09-03T11:30:29Z")

</div>

Why not use \<@fmt.formatDate … \> or one of the freemarker builtins?

[https://freemarker.apache.org/docs/ref\_builtins\_date.html](https://freemarker.apache.org/docs/ref_builtins_date.html)

> **[Writing Generic Templates - Bloomreach Experience - Open Source CMS](https://documentation.bloomreach.com/14/library/concepts/component-development/writing-generic-jsp-pages.html)**
>
> Open Source Enterprise Content Management
