I’d like to see what people think about allowing Zola’s built-in load_data
function to also take a string literal? To be clear, currently you can do:
{# from path: #}
{% set data = load_data(path="content/blog/story/data.toml") %}
{# from url: #}
{% set response = load_data(url="https://api.github.com/repos/getzola/zola") %}
However you can not do the following
{# From a literal #}
{% set data = load_data(str='{ "name": "bob", "age": 42 }', format="json") %}
I would find this to be useful, and make Zola more flexible.
For example, if I have a list of “comment” objects, each with timestamp
and id
fields, I’d find it very useful and flexible to be able to process this list by updating the parent comments with their child’s latest timestamp
, for ordering the comments in a certain order.
Of course there are other ways to do this, but they’re not so good in this specific case, compared to something simple as I suggested above.
In general, being able to load objects is useful, which is why we have the ability to do it from the file system. Therefore, being able to load an object from a string literal would be useful much for the same reasons.
If the reason against having this is to discourage creation of objects at runtime, then that is already made possible via the load_data(url)
option, where you could submit a POST request, and pass in the data as an argument, to have the server echo it back. So the Pandora’s box of creating objects at runtime has been opened already, in a way, if you understand my meaning.
But what do others think? If the reception is positive, I will do the work to add this functionality.