Closed TxHawks closed 9 years ago
It's too late to import data once you're rendering the template. Anything in _data
should be imported regardless.
If you're trying to only use data from section-news.son
I think you're going to have to look into Twig's merge
function. I haven't tested this at all but you could have _data/section-news.json
look like:
{ "section-news: { "news": {
"articles": [ { "title": "foo", "body": "lorem" }, { "title": "bar", "body": "ipsum" } ]
} } }
And then:
{% if section == "news" %}
{% set _context = _context|merge(_context.section-news) %}
{% endif %}
That should bubble up the section-news
stuff to the top of the context stack.
@dmolsen -
Thanks, didn't know that anything in _data
gets imported.
Though , from a very simple test I ran, I think there is no need to merge - any key defined in a json
that resides inside _data
is already part of _context
.
That's a "new" feature that hasn't been documented.
Is it possible to import variables for a pattern from several
json
files? I'm building a rather complex app where a page inherits from the section it reside in.I'd like to have
json
files for each section and do something like: