diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aea0e20..03f2fd66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ - You can now access outer loop's scope by labeling it: `{% outer: for ... %}... {% for ... %} {{ outer.counter }} {% endfor %}{% endfor %}`. [Ilya Puchka](https://github.com/ilyapuchka) [#175](https://github.com/stencilproject/Stencil/pull/175) +- Allow providing lazily evaluated context data, using the `LazyValueWrapper` structure. + [David Jennes](https://github.com/djbe) + [#324](https://github.com/stencilproject/Stencil/pull/324) ### Deprecations diff --git a/docs/templates.rst b/docs/templates.rst index 0e605afd..fcef8362 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -50,6 +50,14 @@ For example, if you have the following context: The result of {{ item[key] }} will be the same as {{ item.name }}. It will first evaluate the result of {{ key }}, and only then evaluate the lookup expression. +You can use the `LazyValueWrapper` type to have values in your context that will be lazily evaluated. The provided value will only be evaluated when it's first accessed in your template, and will be cached afterwards. For example: + +.. code-block:: swift + + [ + "magic": LazyValueWrapper(myHeavyCalculations()) + ] + Filters ~~~~~~~