Skip to content

Example of passing a structs to HTML Template #446

Closed Answered by rubiktubik
rubiktubik asked this question in Q&A
Discussion options

You must be logged in to vote

I have found a solution by myself :-) , after I saw that this package is being used:
https://keats.github.io/tera/docs/

#[derive(Serialize)]
struct Response {
    articles: Vec<Model>,
}

pub fn home(v: impl ViewRenderer, articles: Vec<Model>) -> Result<impl IntoResponse> {
    format::render().view(&v, "home/index.html", Response { articles })
}

The "trick" is to wrap your data with an additional struct.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rubiktubik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant