Skip to content

Change CSS variable with Nunjucks? #1457

Answered by Ryuno-Ki
cmcknight asked this question in General
Discussion options

You must be logged in to vote

I quote myself from Discord :-)

This was the example brought up in Discord:

test.md:

---
title: Test Background
layout: test.njk
bg-image: '/img/hp-background.jpg'
---

{% if bg-image %}
<style>
.bg {
  background: #fff url({{ bg-image }}) no-repeat center center/cover;
  height: 100vh;
}
</style>
{% endif %}
<div class="bg">
</div>

test.njk

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <!DOCTYPE html>
  <style>
    * {
        box-sizing: border-box;
        padding: 0;
        margin: 0;
      }

    body, html {
      height: 100vh;
    }
  

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by cmcknight
Comment options

You must be logged in to vote
1 reply
@cmcknight
Comment options

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