Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.44k stars 280 forks source link

set the number of loop values #783

Closed mothsART closed 1 year ago

mothsART commented 1 year ago

Hi,

I want to use Tera for a project who generate fake datas (using https://crates.io/crates/fake)

Ideally, I will manage all the things with a simple template file (user input).

For example :

{% set peoples.nb = 5 %}

{% for people in peoples %}
  {{ people.firstName }}
  {{ people.lastName }}
{% endfor %}

I would like to force the generation of a list of 5 entries.

Is there a solution to use setters ? For getters, I do :

let mut context = Context::new();
context.insert("fakeData", &getFakeData());

Thanks

Keats commented 1 year ago

You can't do that. You can use range(start=0, end=5) as your loop but not like you're doing in your example

mothsART commented 1 year ago

Ok, I think, the best ways is to create my own parser and collect this values on a first step.

Thanks for your answer