Liquid with struct



examples/liquid/liquid-with-struct/Cargo.toml
[package]
name = "liquid-hello-world"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
liquid = "0.26"
serde = { version = "1.0", features = ["derive"] }

examples/liquid/liquid-with-struct/src/main.rs
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct Car {
    manufacturer: String,
    electric: bool,
    gears: i8,
    names: Vec<String>,
}

fn main() {
    let template = liquid::ParserBuilder::with_stdlib()
        .build()
        .unwrap()
        .parse(
            "
            Car manufacturer: {{car.manufacturer}}
            {% if car.electric %}
                electric
            {% endif %}
            Gears: {{car.gears}}
            {% for name in car.names %}
               {{name}}
            {% endfor %}
        ",
        )
        .unwrap();

    let car = Car {
        manufacturer: String::from("Ford"),
        electric: false,
        gears: 5,
        names: vec![String::from("Mustang"), String::from("Anglia")],
    };
    //println!("manufacturer: {}", car.manufacturer);
    //println!("electric: {}", car.electric);

    let globals = liquid::object!(
    {
        "car": car, //liquid::to_object(&car),
    });
    let output = template.render(&globals).unwrap();

    println!("{}", output);
}


            Car manufacturer: Ford
            
            Gears: 5
            
               Mustang
            
               Anglia