Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double for-loop can not be used? #51

Closed
hhatto opened this issue Sep 2, 2016 · 6 comments
Closed

Double for-loop can not be used? #51

hhatto opened this issue Sep 2, 2016 · 6 comments

Comments

@hhatto
Copy link

hhatto commented Sep 2, 2016

main.rs

extern crate tera;
use std::env;
use std::path::Path;
use tera::{Tera, Context};

fn main() {
    let root_path = env::current_dir().unwrap();
    let template_dir = root_path.join(Path::new("templates/*"));
    let template_engine = Tera::new(template_dir.to_str().unwrap());
    let mut context = Context::new();

    let vectors = vec![vec![0, 3, 6], vec![1, 4, 7]];
    context.add("vectors", &vectors);
    println!("{}", template_engine.render("double-loop.tera", context).unwrap());
}

templates/double-loop.tera:

{% for vector in vectors %}
  {% for j in vector %}
    j={{ j }}
  {% endfor %}
{% endfor %}

output:

j=0
  j=3
  j=6
j=0
  j=3
  j=6

P.S.

tera is good library 😄
I have been using in the build script.

Thanks.

@Keats
Copy link
Owner

Keats commented Sep 2, 2016

Thanks for the bug report! I'll have a look later today or this weekend

@Keats
Copy link
Owner

Keats commented Sep 2, 2016

It's fixed in master if you want to try, I'll try to get a release out in a couple of days once we have more filters (#46)

@hhatto
Copy link
Author

hhatto commented Sep 5, 2016

Thanks.
I was able to confirm that it is fixed in the master.

@hhatto
Copy link
Author

hhatto commented Sep 5, 2016

@Keats
I found another problem.
It does not work correctly, when there is empty vector in for-loop.

patch this: hhatto@8b4684c

@Keats
Copy link
Owner

Keats commented Sep 5, 2016

Thanks, I pushed the fix to master!

@hhatto
Copy link
Author

hhatto commented Sep 5, 2016

Thank you very much 😃

@hhatto hhatto closed this as completed Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants