Uploaded image for project: 'Apache Freemarker'
  1. Apache Freemarker
  2. FREEMARKER-84

Improve include directive to detect whether template exists

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Implemented
    • 2.3.27-incubating
    • 2.3.28
    • engine
    • None

    Description

      I requested feature `ignore_missing=true` of <#include> and freemarker have implemented it, but it cannot handle fallback like

      <#assign path="relative.ftl">
      <#if isTemplatePresent(path)>
      <#include path>
      <#else>
      template "${path}" is not exists
      </#if>
      

      Proposal 1:
      Introduce a new special variable like "template_included" similar to "$?" of shell exit code

      <#include path ignore_missing=true>
      <#if !.template_included>
      template "${path}" is not exists
      </#if>
      

      Proposal 2:
      Add an argument like "template_included" for include directive

      <#include path ignore_missing=true template_included="pathExists">
      <#if !pathExists>
      template "${path}" is not exists
      </#if>
      

      Proposal 3:
      Introduce a new special directive such as <#missing> similar to html <noscript> tag

      <#include path>
      <#missing>
      template "${path}" is not exists
      </#missing>
      </#include>
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            quaff Yanming Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: