Ivan -Oats- Storck
Ivan -Oats- Storck

Reputation: 4326

How do I use the HexoJS css helper from a nunjucks template?

I get the error:

Unhandled rejection Template render error: (unknown path) [Line 9, Column 6]
  unknown block tag: css
    at Object.exports.withPrettyErrors (/Users/me/hexo-site/node_modules/hexo-renderer-nunjucks/node_modules/nunjucks/src/lib.js:35:17)

My themes/theme-name/layout/layout.nunjucks file has this code:

<title>Site title</title>
{% css "css/style.css" %}

Upvotes: 1

Views: 351

Answers (1)

somebody
somebody

Reputation: 430

Nunjucks does not have a css tag, and it doesn't look like hexo-renderer-nunjucks implements one either.

You can implement it yourself, but it looks easier to just use a filter:

env.addFilter('css', function(str) {
    return '<link rel="stylesheet" href="' + str + '"></link"'
})

and use {{"css/style.css"|css}} instead.

Upvotes: 3

Related Questions