Uploaded image for project: 'Magnolia Demo Projects'
  1. Magnolia Demo Projects
  2. MGNLDEMO-22

Freemarker Scripts: Should be simplified and best practices should be used

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Obsolete
    • Major
    • None
    • 0.5
    • magnolia-travels
    • None

    Description

      I see in many scripts parts which are either too complicated or do not use scripting best practices.
      This should be changes to make the readability and understandability much better.

      One example (textImage.ftl):
      Original

      [#assign headingLevel = "h2"]
      [#if content.headingLevel?has_content]
          [#assign headingLevel = content.headingLevel]
      [/#if]
      
      [#if content.headline?has_content]
          <${headingLevel}>${content.headline!}</${headingLevel}>
      [/#if]
      

      Replacing with (using properly "!"):

      [#assign headingLevel = content.headingLevel!"h2"]
      [#if content.headline?has_content]
          <${headingLevel}>${content.headline}</${headingLevel}>
      [/#if]
      

      Better would be even delegating to the parameters def the default heading level.
      Like this more variations could be created using a different default heading level:

      [#assign headingLevel = content.headingLevel!def.parameters.defaultHeadingLevel!"h2"]
      [#if content.headline?has_content]
          <${headingLevel}>${content.headline}</${headingLevel}>
      [/#if]
      

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                ejervidalo Espen Jervidalo
                cringele Christian Ringele
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Task DoD