5

I'm trying to set a background-img in my css.liquid file, and I need to get YAML variables in the page. How can I do that? This is what I have so far:

background-image: url({{ page.locales[page.default_locale][page.first_name] }});

I also had this:

background-image: url('{{ page.first_name }}{{ page.last_name }}.jpg');
irosenb
  • 828
  • 2
  • 13
  • 26

3 Answers3

2

Just use these styles 'inline' and not in your css.liquid file. That is by far the easiest (and least ugly) solution.

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
1

Only files with a YAML front matter section, and with the extensions .html, .markdown, .md, or .textile get processed by Jekyll.

You could hack this to get it working by saving your CSS file with one of those extensions, and including a YAML front matter section. That seems like a pretty clumsy way to do it, and it'll make for some ugly code, but it might work.

Brian Willis
  • 22,768
  • 9
  • 46
  • 50
0

You need to add ---\n--- at the top of the css file, like so:

---
---

.myClass {
   background-image: url('{{ page.first_name }}{{ page.last_name }}.jpg');
}

As mentioned here: https://stackoverflow.com/a/42528645/2235593

Community
  • 1
  • 1