Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline external CSS with Handlebars #732

Closed
KiwiKilian opened this issue Jan 7, 2022 · 2 comments
Closed

Inline external CSS with Handlebars #732

KiwiKilian opened this issue Jan 7, 2022 · 2 comments

Comments

@KiwiKilian
Copy link

KiwiKilian commented Jan 7, 2022

The documentation about how to inline external CSS is very dense. This merge request suggests, it should work to include a CSS file with a normal a <link>:

<link rel="stylesheet" href="style.css" />

My templates/handlebars config looks like this:

template: {
  dir: __dirname + '/templates',
  adapter: new HandlebarsAdapter(),
  options: {
    strict: true,
  },
}

My templates and the style.css reside in the same directory templates. Sending the template without <link> tag works as expected, also putting all the CSS in a <style> works with the inlining.

When including the external CSS file like shown a the beginning throws the following error:

Error: getaddrinfo ENOTFOUND style.css
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)

The adapter config shown in the docs also doesn't change anything and seem to reflect the default config. As it seems to be a path resolving issue I tried quite a few paths in the <link> but nothing like style.css, ./style.css, /style.css or with templates prefixed seemed to work.

@dantehemerson
Copy link
Member

@KiwiKilian You have to send the path to the folder prefixed with file://, like this:

adapter: new HandlebarsAdapter(undefined,  {
  inlineCssOptions: {
    url: `file://` + process.cwd() + '/templates/',
  },
}),

@f-albuquerque
Copy link

f-albuquerque commented Aug 2, 2023

This worked for me:

template: {
    dir: path.join(__dirname, '/assets/mailer-templates'),
    adapter: new HandlebarsAdapter(undefined, {
        inlineCssOptions: {
            url: 'file://' + path.join(__dirname, '/assets/mailer-templates/style.css'),
        },
    }),
    options: {
        strict: true,
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants