Skip to content

Allow renderFile or equivalent to fail silently if file does not exist #3051

@thedamon

Description

@thedamon

Is your feature request related to a problem? Please describe.

I want to pull in files dynamically, associating markdown descriptions of taxonomies and other things like so:

{%- set desc = "./_meta/tags/" + tag + ".md" -%}
<div>{% renderFile desc %}</div>

In this scenario, though, if the tag does not exist eleventy will fail to build.

Describe the solution you'd like

It seems potentially useful to be able to opt not to fail if the file is not there today. Probably best would be an additional shortcode that has a try/catch in it:

{% renderFileIfExists desc %}

Nunjucks as an option in include: {% include "missing.html" ignore missing %}

Describe alternatives you've considered

A simple way to check the existence of the file in another variable or maybe more helpfully overall adding a custom

{% try %} block to supported templating languages then I could instead do

{% try %} <div>{% renderFile desc %}</div> {% endtry %}

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions