Skip to content

Returning errors from templates #662

Closed Answered by a-h
tarndt asked this question in Q&A
Apr 2, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

The idea was that you'd have created a view model already, and wouldn't be doing logic that can fail inside a template, just like http.Handler doesn't return an error.

The idea of view models is briefly touched on in https://templ.guide/core-concepts/view-models.

In your case I'd make a model that doesn't use the iterator directly, but instead, copies the results to a slice for display.

templ x() { components basically elide the implicit return. When Go gets yield statements, maybe it will be time to reconsider it, since there will be more options.

In a code component, you can do whatever you want, of course. 😀

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by tarndt
Comment options

You must be logged in to vote
1 reply
@a-h
Comment options

a-h Jun 22, 2024
Maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants