Generate inline style attributes with Tailwind CSS
Tailwind Inline aims to create a cohesive development experience, whether you’re using templates to build a web application or an HTML email.
Because most email clients block external and internal CSS, it’s essential to use inline style CSS when developing HTML email templates.
import(
"os"
"log"
"context"
"github.com/a-h/templ"
twi "github.com/gavink97/tailwind-inline"
)
path := "./public/styles.css"
styles, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
component := yourTemplComponent
s, err := templ.ToGoHTML(ctx, component)
if err != nil {
log.Fatal(err)
}
c := twi.Convert(string(s), styles)
import(
"os"
"io"
"log"
"bytes"
"html/template"
twi "github.com/gavink97/tailwind-inline"
)
path := "./public/styles.css"
styles, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
var b bytes.Buffer
tpl := yourTemplate
t, err := template.New("Email").Parse(tpl)
if err != nil {
log.Fatal()
}
data := struct {
Title string
}{
Title: "My email",
}
buff := io.Writer(&b)
err = t.Execute(buff, data)
c := twi.Convert(b.String(), styles)