cancel
Showing results for 
Search instead for 
Did you mean: 

Date format in a FreeMarker Template

rguedes
Champ in-the-making
Champ in-the-making
Hi, folks!

I am trying to use the following code to format a date field to the Brazilian fomat ("DD/MM/YYYY"):

${news.PublishedDate.string("yyyy-MM-dd")}

But, when Alfresco render the web form content, I get this error:


Error generating rendition using radio_final.ftl: freemarker.template.TemplateException: Expected method. radionovo.DataPublicacao.string evaluated instead to freemarker.ext.dom.NodeListModel on line 71, column 19 in freemarker_template.

What could be wrong? Is there another way to do this formatting?

Tks!
5 REPLIES 5

patil
Champ on-the-rise
Champ on-the-rise
Hi Try this,

"${news.PublishedDate?datetime?string("yyyy-MM-dd")}"

Thanks,
Patil
Cignex Technologies
Bangalore

rptester
Champ in-the-making
Champ in-the-making
Hi
I tried the way you suggested for formatting my date, but I got the following exception

   
Error generating rendition using news.ftl: freemarker.core.NonStringException: Error on line 236, column 104 in freemarker_template
Expecting a string, date or number here, Expression press_release.launch_date is instead a freemarker.ext.dom.NodeListModel

Here is my the line that throws that error.

${press_release.launch_date?datetime?string("MMM dd, yyyy")}

Can you let me know what I am doing wrong here.

Thanks

patil
Champ on-the-rise
Champ on-the-rise
Hi

Expecting a string, date or number here, Expression press_release.launch_date

Looks like launch_date is not String or date. It is collection.

Thanks,
Patil
Cignex Technologies
Bangalore

rptester
Champ in-the-making
Champ in-the-making
I dont think it is a Collection, unless I am missing something. here is my xsd file for the web form.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:pr="http://www.alfresco.org/alfresco/pr" xmlns:alf="http://www.alfresco.org"
           targetNamespace="http://www.alfresco.org/alfresco/pr"
           elementFormDefault="qualified">

  <!– defines the form for creating a press release –>
  <xs:element name="press_release">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" type="xs:normalizedString"/>
      
        <xs:element name="body" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
      
   <xs:element name="launch_date" type="xs:date"/>
   <xs:element name="expiration_date" type="xs:date"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Please let me know how to format the date value in "launch_date" which is in "MM/DD/YYYY" format to "MMM DD, YYYY".

Thanks

rptester
Champ in-the-making
Champ in-the-making
Ahh figured it out.

Ftl rendering engine was returning date as a string in "yyyy-mm-dd" format. I had to convert it to date value in the same format to render it "MMM dd, yyyy" format. For eg.
${press_release.launch_date?date("yyyy-MM-dd")}


Hope this helps to someone else.

Cheers