# Is it possible to change a page's document's fields in an ftl template using freemarker?

**URL:** <https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [April 11, 2022, 9:21pm UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139 "2022-04-11T21:21:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Georgi\_Andonov](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/georgi_andonov/32/1262_2.png) [@Georgi\_Andonov](https://community.bloomreach.com/u/Georgi_Andonov)\
**Post date:** [April 11, 2022, 9:21pm UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139/1 "2022-04-11T21:21:54Z")

</div>

Hello! I was wondering if it is possible to change the content of a specific document using an ftl snippet? I am currently trying to fetch some data from a database using javascript and override a document that is inside a container on a page.

---

<div class="post-metadata">

**Author:** ![tobijeger](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/tobijeger/32/291_2.png) [@tobijeger](https://community.bloomreach.com/u/tobijeger)\
**Post date:** [April 12, 2022, 7:44am UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139/2 "2022-04-12T07:44:18Z")

</div>

Hi Georgi, I have moved your question into the Experience Manager category, believing that your question was not related to the SaaS version of Bloomreach Content. If I was mistaken, please provide some additional details about your setup and use case, because I’m not sure what you mean by “change the content of a specific document”. Do you want that change to be persisted in the database, to affect future use of that document, or do you want the change to affect only the a specific page request response (the “delivery”)?

---

<div class="post-metadata">

**Author:** ![Georgi\_Andonov](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/georgi_andonov/32/1262_2.png) [@Georgi\_Andonov](https://community.bloomreach.com/u/Georgi_Andonov)\
**Post date:** [April 12, 2022, 8:32am UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139/3 "2022-04-12T08:32:18Z")

</div>

Hi! I apologize for the wrong category. Now I have a page that has a container that contains a document whose fields are empty (it has several string fields like “firstname”, “secondname”, etc.) and I want to populate them with values coming from an outside database using freemarker if possible. I want those changes to be saved in the specific document and I want this change to affect every usage of this document.

---

<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:** [April 12, 2022, 9:55am UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139/4 "2022-04-12T09:55:57Z")

</div>

Why not prepopulate them? Presumably you don’t want this to happen on every call to the page? You only need to populate that once. I may not understand what you are trying to achieve. But I would do this either as a workflow action on save or publish, or as logic in a server side java component (either on the get or as reaction to a post).

---

<div class="post-metadata">

**Author:** ![Georgi\_Andonov](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/georgi_andonov/32/1262_2.png) [@Georgi\_Andonov](https://community.bloomreach.com/u/Georgi_Andonov)\
**Post date:** [April 12, 2022, 10:36am UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139/5 "2022-04-12T10:36:03Z")

</div>

Thank you for the response. I was thinking about integrating the request to the database inside a java component and fetching the data there but I was wondering if it was possible to populate empty document fields directly in the ftl template? Let’s say I get access to a document field’s value by doing document.fieldname - is there an option to change the value of document.fieldname?

---

<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:** [April 13, 2022, 8:12am UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139/6 "2022-04-13T08:12:36Z")

</div>

You cannot change document fields in an ftil template. You will always need a call to the server to do that.

---

<div class="post-metadata">

**Author:** ![Georgi\_Andonov](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/georgi_andonov/32/1262_2.png) [@Georgi\_Andonov](https://community.bloomreach.com/u/Georgi_Andonov)\
**Post date:** [April 18, 2022, 3:59pm UTC](https://community.bloomreach.com/t/is-it-possible-to-change-a-pages-documents-fields-in-an-ftl-template-using-freemarker/3139/7 "2022-04-18T15:59:55Z")

</div>

@jasper.floor  
Hello, Jasper! I am currently working with prepopulating my data into a component’s fields in a java class. I’ve set up connection to my database server and am fetching the data correctly. However, I do not seem to find how I am supposed to set the fetched values to my newly created document. My class extends CommonComponent abstract class and I am wondering where should I create my custom setter methods?

Thanks,  
Georgi
