You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Daniel Dekany (JIRA)" <ji...@apache.org> on 2018/02/11 21:13:00 UTC

[jira] [Commented] (FREEMARKER-84) Improve include directive to detect whether template exists

    [ https://issues.apache.org/jira/browse/FREEMARKER-84?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16360127#comment-16360127 ] 

Daniel Dekany commented on FREEMARKER-84:
-----------------------------------------

I have started working implementing {{.last_include_found}}, and realized that it's not a very good solution after all. See [https://lists.apache.org/thread.html/0bc90b453f106adfdb6ba1fc91cbbb63daa386be3fe7e2463362a2bd@<dev.freemarker.apache.org>|https://lists.apache.org/thread.html/0bc90b453f106adfdb6ba1fc91cbbb63daa386be3fe7e2463362a2bd@%3Cdev.freemarker.apache.org%3E], and don't hesitate to add your thoughts there.

> Improve include directive to detect whether template exists
> -----------------------------------------------------------
>
>                 Key: FREEMARKER-84
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-84
>             Project: Apache Freemarker
>          Issue Type: Improvement
>          Components: engine
>    Affects Versions: 2.3.27-incubating
>            Reporter: Yanming Zhou
>            Priority: Major
>
> I requested feature `ignore_missing=true` of <#include> and freemarker have implemented it, but it cannot handle fallback like
> {code}
> <#assign path="relative.ftl">
> <#if isTemplatePresent(path)>
> <#include path>
> <#else>
> template "${path}" is not exists
> </#if>
> {code}
> Proposal 1:
> Introduce a new special variable like "template_included" similar to "$?" of shell exit code
> {code}
> <#include path ignore_missing=true>
> <#if !.template_included>
> template "${path}" is not exists
> </#if>
> {code}
> Proposal 2:
> Add an argument like "template_included" for include directive
> {code}
> <#include path ignore_missing=true template_included="pathExists">
> <#if !pathExists>
> template "${path}" is not exists
> </#if>
> {code}
> Proposal 3:
> Introduce a new special directive such as <#missing> similar to html <noscript> tag
> {code}
> <#include path>
> <#missing>
> template "${path}" is not exists
> </#missing>
> </#include>
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)