-
-
Save shopifypartners/d66e0725687a195a2d49974b535f8025 to your computer and use it in GitHub Desktop.
A Beginner's Guide to Sass with Shopify — Part 3: Sass interpolation, Workflow and Object Oriented CSS - https://www.shopify.com/partners/blog/a-beginners-guide-to-sass-with-shopify-part-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Escaping Liquid in SCSS. | |
// | |
// Expected output: | |
// a{ | |
// color: {{ settings.link-color }}; | |
// } | |
a{ | |
color: #{'{{ settings.link-color }}'}; | |
} | |
// Reuasble liquid: | |
$myVar: #{'{{ settings.font-family }}'}; | |
h1{ | |
font-family: $myVar; | |
} | |
// Using a sass variable from the current file: | |
$var1: #fff; | |
$var2: #{'{% if settings.colour %}{{ settings.colour }}{% else %}'}$var1#{'{% endif %}'}; | |
// Liquid if statement: | |
body{ | |
/* {% if settings.background-image %} */ | |
background: url(#{'{{ settings.background-image | asset_url }}'}) center no-repeat; | |
/* {% else %} */ | |
background: whitesmoke; | |
/* {% endif %} */ | |
} | |
// Liquid outside a css statement: | |
// If we wrote /* {{ settings.custom-css }} */ then our compiled liquid would be inside the comments making it useless. | |
// We need liquid to create the ending and opening comments when its compiled, | |
// however if we wrote /* {{ settings.custom-css | prepend: '*/' | append: '/*' }} */ the string: ' | append: ' | |
// is still seen as being outside the comments. | |
// We need to escape them untill liquid can create them so we add an extra character and then remove it. | |
/* {{ settings.custom-css | prepend: '*\/' | append: '\/*' | remove: '\' }} */ | |
/* {% if settings.custom-css %}{{ settings.custom-css | prepend: '*\/' | append: '\/*' | remove: '\' }}{% endif %} */ |
How would you escape a url for something like this?
src:url('{{ 'theme-icons.eot' | asset_url }}');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a great example! I have one question, how do I add multiplication to font sizes in settings. For example:
At the moment when I try this example, I get
font-size: 13px5;
whereas I would like it to outputfont-size: 18px;
Thanks again for the example.