Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.