mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 634 forks source link

docs: add example how to set a var from file include #1439

Open MentalGear opened 1 year ago

MentalGear commented 1 year ago

Faced this issue for days, until I found this in some outside code example. I think it should be clearer that outside files can be included and transformed using a var, especially since the expected idiomatic approach ({% set example_output = include 'example.json' % }) does not work.

Summary

Proposed change:

Add example to the docs:

{% set fileAsVar %}
     {% include 'example.json' %}
{% endset %}

Checklist

I've completed the checklist below to ensure I didn't forget anything. This makes reviewing this PR as easy as possible for the maintainers. And it gets this change released as soon as possible.