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

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.

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”)?

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.

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).

1 Like

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?

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

1 Like

@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