How to use css assets?
Closed this issue · 1 comments
real-artswan commented
Can not figure out how I can include css file from assets to the template.
Tried with
doctype html
html(lang="en")
style
!{{#asset styles.css @encoding=utf8}}
head
body
And with
doctype html
html(lang="en")
style
| {#asset styles.css @encoding=utf8}
head
body
How is it supposed to do this?
bjrmatos commented
hi! here is an example, unfortunately, the asset insertion does not work good by default with space-sensitive engine like Pug, so the solution is to use a helper to remove the lines, after that you see it works.
doctype html
html(lang="en")
style
| #{templateHelpers.getStylesWithoutNewLines()}
head
body
h1 text in another color
h2 text in different color
// helpers
function getStylesWithoutNewLines () {
const styles = `{#asset styles.css @encoding=utf8}`
return styles.replace('\n', ' ')
}