Menu

#87 add option ignoreNotFound for directive include for safety

2.3.21
closed-fixed
None
5
2014-10-16
2013-03-24
Anonymous
No

<#include path="/maynotexists.ftl" ignoreNotFound=true/>

Discussion

  • Dániel Dékány

    Tell me a bit more about this. What exactly is the use-case for this, why do you need this? Why would you just do nothing if that file is missing? If the file is known to be optional, certainly its surrounding also have to be different if it's missing. So it sounds more like there should be a way to *check* if a template is missing (<#if "/maynotexists.ftl"?template_exists >...<#else>...</#if> or like), so then you can chose a different route.

     
  • Anonymous

    Anonymous - 2013-03-25

    I have created a web framework,I am using sitemesh and freemarker as decorator page,In my decorator page,I have preserve some placeholder let application to override or implement.
    for example:

    <html>
    <head>
    <title>${title}</title>
    <meta charset="utf-8">
    <#include "include/assets.ftl"/>
    ${head}
    </head>
    <body>
    <#include "include/top.ftl"/>
    ${body}
    <#include "include/bottom.ftl"/>
    </body>
    </html>

    assets.ftl top.ftl and bottom.ftl may not exists in some projects,if have no ignoreNotFound,it will throws Exception.
    this feature somehow like spring SPEL for placeholder, ${database.password:},if database.password doesn't exists in properties file,append a colon to make it safe.
    I have considered <#attempt>attempt block<#recover>recover block</#attempt>,it works fine but throws Exception in console every time.

     
  • Dániel Dékány

    Clearly something will have to be done to support optional includes, but just silently skipping the inclusion will not be enough for many. Anyway, certainly there won't be much non-bugfix development until the summer. Until that, note that a custom directive (just implement TemplateDirectiveModel) can do this, as the Environment API has getTemplateForInclusion and such.

     
    • zhouyanming

      zhouyanming - 2013-11-25

      Hi,is there any updates?

       
  • Dániel Dékány

    Nope... I mean, it's question of time, but time is exactly what developers don't have...

     

    Last edit: Dániel Dékány 2013-11-25
  • zhouyanming

    zhouyanming - 2014-09-02

    Hi, please consider this feature, It's very important for me.

     
  • Dániel Dékány

    • status: open --> open-accepted
    • assigned_to: Dániel Dékány
    • Group: --> 2.3.21
     
  • Dániel Dékány

    Starting from 2.3.21 it has ignore_missing=boolean. (There's no way to specify a fall back yet... but that wasn't part of this RFE.)

     
  • Dániel Dékány

    • status: open-accepted --> closed-fixed
     

Log in to post a comment.

Auth0 Logo