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

Freemarker repeatable fields syntax issue

    Details

      Description

      There is an issue with the template editor when creating web content templates with regards to repeatable fields. The ?has_content built in seems to assume that the field is present in the versioned item of content in the database. It might not be.

      This is the default code Liferay Template editor gives:

      <#if Repeated.getSiblings()?has_content>
        <#list Repeated.getSiblings() as cur_Repeated> ${cur_Repeated.getData()} </#list>
      </#if>
      

      This is failing because it assumes the data is there so has_content alone isn't safe. Though to be fair I'm a bad template developer and now I've copied this all over my portal.

       

      This is the code assumes the field is not there, so template doesn't error

      <#if (Repeated.getSiblings())?? && Repeated.getSiblings()?has_content> 
        <#list Repeated.getSiblings() as cur_Repeated> ${cur_Repeated.getData()} </#list>
      </#if>
      

      Could the template editor be updated accordingly making sure to have brackets around the exists builtin. (Repeated.getSiblings())??

       

       

      https://stackoverflow.com/questions/23552151/difference-between-has-content-if-exists-in-freemarker/23553196

       

       

        Attachments

          Activity

            People

            Assignee:
            support-lep@liferay.com SE Support
            Reporter:
            lee.jordan1 Lee Jordan
            Participants of an Issue:
            Recent user:
            David Gutiérrez Mesa
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              33 weeks, 4 days ago

                Packages

                Version Package