so typically I want to do something like
\nc.Render(http.StatusOK, \"template-1\", data1)\nreturn c.Render(http.StatusOK, \"template-2\", data2)
but sending the status code twice doesn't make sense and I get an error message that says response already committed
. To get around that I've been doing something like
c.Render(http.StatusOK, \"template-1\", data1)\nreturn c.Echo().Renderer.Render(c.Response().Writer, \"template-2\", data2, c)
Is there a function I'm missing or more idiomatic approach to handling situations like these? I'm relatively new to golang. Thanks!
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Go templates can include other templates. so you could create template 3 that includes template 1 and template2 and render that.
","upvoteCount":2,"url":"https://github.com/labstack/echo/discussions/2686#discussioncomment-10951577"}}}-
I have an app which uses htmx and I often need to render a main response body plus some out-of-band content to swap out for a different part of the page, in a single response body <!-- Template 1 --><div>Main template content</div>
<!-- Template 2 --><div id="other-part" hx-oob-swap="true">Some other part</div> so typically I want to do something like c.Render(http.StatusOK, "template-1", data1)
return c.Render(http.StatusOK, "template-2", data2) but sending the status code twice doesn't make sense and I get an error message that says c.Render(http.StatusOK, "template-1", data1)
return c.Echo().Renderer.Render(c.Response().Writer, "template-2", data2, c) Is there a function I'm missing or more idiomatic approach to handling situations like these? I'm relatively new to golang. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Go templates can include other templates. so you could create template 3 that includes template 1 and template2 and render that. |
Beta Was this translation helpful? Give feedback.
Go templates can include other templates. so you could create template 3 that includes template 1 and template2 and render that.