Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shopifypartners/d66e0725687a195a2d49974b535f8025 to your computer and use it in GitHub Desktop.
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
// 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 %} */
@YewTreeWeb
Copy link

YewTreeWeb commented Jun 21, 2017

This is a great example! I have one question, how do I add multiplication to font sizes in settings. For example:

$font-base: #{'{{ settings.type_base_size }}'};
$font-lg: $font-base + 5;

At the moment when I try this example, I get font-size: 13px5; whereas I would like it to output font-size: 18px;

Thanks again for the example.

@joshuaiz
Copy link

joshuaiz commented Feb 9, 2018

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