cancel
Showing results for 
Search instead for 
Did you mean: 

Can I read txt file with ftl?

msvoren
Champ in-the-making
Champ in-the-making
Is there a way to read file content with ftl?

I need to read txt file published on the internet.

E.g. http://www.server.com/mydoc.txt

I would like to display content of this file within my template. Anybody?
1 REPLY 1

pmonks
Star Contributor
Star Contributor
Freemarker doesn't natively include any mechanisms for reading data - being a pure templating language it expects the template to be passed all of the data that it needs in order to do its job (see http://freemarker.org/docs/dgui_quickstart_basics.html for background on why Freemarker was designed this way).

In the context of Alfresco Web Scripts, this means that any data that your Freemarker template requires must be provided by the controller of the Web Script (either the Javascript script or Java class, depending on how the Web Script was implemented).

So for the use case you describe,  the text file would be retrieved by the Web Script controller (JS or Java) and its contents added to the special "model" variable as a new property, thereby making it available to the Freemarker template for further markup.

Cheers,
Peter