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

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

      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]
      

        Acceptance criteria

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

                Created:
                Updated:
                Resolved:

                  Task DoD