Skip to content

Instantly share code, notes, and snippets.

@Jetroid
Created July 29, 2016 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jetroid/bd71e5bbc2de763d0973e706efc91d7c to your computer and use it in GitHub Desktop.
Save Jetroid/bd71e5bbc2de763d0973e706efc91d7c to your computer and use it in GitHub Desktop.
A hacky Liquid script to allow page-specific stylesheets using Yaml Front Matter
---
---
{% assign delim = "|" %}
{% assign had_elements = "" %}
<!-- Custom Stylesheets - use custom_css in YAML front matter !-->
{% if page.custom_css %}
{% for stylesheet in page.custom_css %}
{% capture had_elements %}{{ had_elements | join: delim }}{{ delim }}{{ stylesheet }}{% endcapture %}
{% assign had_elements = had_elements | split: delim %}
<link rel="stylesheet" href="/assets/css/{{ stylesheet }}.css" type="text/css">
{% endfor %}
{% endif %}
{% if layout.custom_css %}
{% for stylesheet in layout.custom_css %}
{% if had_elements contains stylesheet %}{% else %}
<link rel="stylesheet" href="/assets/css/{{ stylesheet }}.css" type="text/css">
{% endif %}
{% endfor %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment