Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-91279

Invalid Freemarker code is generated in template editor when using embedded date fields

    Details

      Description

      Reproduction steps

      1. Start the latest master
      2. Create a new site
      3. Create a new structure "struct1" with a Date field embedded into another one, e.g.: add a Text field named "T1" and inside that a Date field named "D1"
      4. Click "Manage Templates" on struct1 and "Add" to open the template editor
      5. Click "D1" on the left side, and a code like this will be added to the editor:
        <#assign T1.D1_Data = getterUtil.getString(T1.D1.getData())>
        
        <#if validator.isNotNull(T1.D1_Data)>
        	<#assign T1.D1_DateObj = dateUtil.parseDate("yyyy-MM-dd", T1.D1_Data, locale)>
        
        	${dateUtil.getDate(T1.D1_DateObj, "dd MMM yyyy - HH:mm:ss", locale)}
        </#if>
        
      6. Save the template
      7. Go to Web Contents, create a new "struct1" web content, fill both fields
      8. Preview the web content

      Expected: the date value of the web content article is shown correctly
      actual: an error is shown instead of the web content:

      An error occurred while processing the template.
      Syntax error in template "20115#20151#36778" in line 1, column 12:
      Encountered ".", but was expecting one of:
          "="
          "+="
          "-="
          "*="
          "/="
          "%="
          "++"
          "--"
          "in"
          ">"
      1<#assign T1.D1_Data = getterUtil.getString(T1.D1.getData())> 
      2 
      3<#if validator.isNotNull(T1.D1_Data)> 
      4	<#assign T1.D1_DateObj = dateUtil.parseDate("yyyy-MM-dd", T1.D1_Data, locale)> 
      5 
      6	${dateUtil.getDate(T1.D1_DateObj, "dd MMM yyyy - HH:mm:ss", locale)} 
      7</#if>
      

      Reproduced on:
      7.1.x : Commit: ee3cc2d128e09e039854f643acc4d3963069dfc0
      Master: Commit: 304c1ae6a8bd439f952ae662954dfef1c58848b0

      Note
      The problem seems to be that the generated FTL code is wrong: "T1.D1_Data" is an invalid variable name in FTL. However, the variable names can contain special characters, when they are escaped with "\": "T1\.D1_Data"

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                32 weeks ago

                Packages

                Version Package
                7.1.10 DXP FP10
                7.1.10.2 SP2
                7.1.3 CE GA4
                7.1.X
                Master