Capture a template output for reasons like sending e-mail?
acidjazz opened this issue · 12 comments
I want to use templates to send e-mails via AWS SES - is this possible with fiber?
I was able to capture the html doing this:
buffer := new(bytes.Buffer)
err := c.App().Config().Views.Render(buffer, "demo", render.H{
"hostname": setting.Core.WebURL,
"demo": params,
})
if err != nil {
return render.Error(c, err.Error())
}
you can also use the template system without the fiber app
Since the email is related to the endpoint (contact form, login button, notifications) it would be nice to do this in fiber.
My above examples is working well, maybe we can add a c.ReturnRender()
or something?
I'll give a PR a shot once I get some time
but there are already several render functions ?
the view engine has one where it assigns the output to a writer, which in the case of fiber is the context output and fiber also has a render method where you can specify which template to render
no extension of functionality needed
My above examples is working well
closed
but there are already several render functions ? the view engine has one where it assigns the output to a writer, which in the case of fiber is the context output and fiber also has a render method where you can specify which template to render
no extension of functionality needed
My above examples is working well
closed
Do any of these functions return the html as a string? AKA what I need ?
https://github.com/gofiber/template/blob/master/html/html.go#L196
no return as string, it gives this string to a writer
all the view engines in our template make that
https://github.com/gofiber/fiber/blob/72397a7c5be7291235261dcf5b079d7702277b65/ctx.go#L135
https://github.com/gofiber/template/blob/master/html/html.go#L196 no return as string, it gives this string to a writer
OK so then how would I use this to get the HTML to send in an email?
How do I go after the engine instance itself?
I find it pretty necessary to be able to route templates to other sources like email - these are standard things API's do.
correct, these are also possible with the frameworks but have to be implemented by yourself
a framework cannot offer solutions for every case, otherwise it becomes too big and overloaded
as said, it is possible using template engine
-> you can put this in a self written function and provide it to others via packages
I see the framework as the solution in this case - I have everything I need to send out my notification/confirmation/contact/etc - I have the logged in user and all of their information
All I have to do next is something like
if _, err := aws.SendEmail(c.Locals("user").email, "Contact Us Form", html); err != nil {
return render.Error(c, err.Error())
}
I think it makes perfect sense this functionality is w/in fiber since you're already providing Templating and this framework is angled towards API's.
To be completely honest I'm building an entirely JSON-only API - so E-mail is the only reason I'm even using Templating