MCPcopy
hub / github.com/labstack/echo / Render

Method Render

context.go:493–511  ·  view source on GitHub ↗

Render renders a template with data and sends a text/html response with status code. Renderer must be registered using `Echo.Renderer`.

(code int, name string, data any)

Source from the content-addressed store, hash-verified

491// Render renders a template with data and sends a text/html response with status
492// code. Renderer must be registered using `Echo.Renderer`.
493func (c *Context) Render(code int, name string, data any) (err error) {
494 if c.echo.Renderer == nil {
495 return ErrRendererNotRegistered
496 }
497 // as Renderer.Render can fail, and in that case we need to delay sending status code to the client until
498 // (global) error handler decides the correct status code for the error to be sent to the client, so we need to write
499 // the rendered template to the buffer first.
500 //
501 // html.Template.ExecuteTemplate() documentations writes:
502 // > If an error occurs executing the template or writing its output,
503 // > execution stops, but partial results may already have been written to
504 // > the output writer.
505
506 buf := new(bytes.Buffer)
507 if err = c.echo.Renderer.Render(c, buf, name, data); err != nil {
508 return
509 }
510 return c.HTMLBlob(code, buf.Bytes())
511}
512
513// HTML sends an HTTP response with status code.
514func (c *Context) HTML(code int, html string) (err error) {

Calls 2

HTMLBlobMethod · 0.95
RenderMethod · 0.65