- Published on
DIY Swatch Magic Unleash the Code and Ditch the Monthly Fee
- Authors
- Name
- Entaice Braintrust
DIY Swatch Magic: Unleash the Code and Ditch the Monthly Fee
There was a time when we wanted everything just right, like a barista perfecting your third latte of the day. We once believed that the best way to achieve this sartorial utopia on Shopify was through an endless array of plugins which kept dangling the perfect swatches before us, only to snatch them back under the guise of a monthly fee, $15— that’s like three cups of caffeine heaven.
But fear not, dear friends, there’s freedom beyond the monetary grasp. Let’s embark on this journey together, transforming our dreams of swatches into a reality, one code snip at a time.
The Lightbulb Moment: Understanding the Jigsaw
Imagine this—a puzzle where all the pieces are swatches. Our first task is simple yet vital—understanding the image we are trying to recreate with our creative tech toolkit. Swatches for colors and sizes, no app required, for the product and collection pages. Chocolates in rectangles—sizes in squares. Big dreams demand even bigger plans.
If you’re like us, you’ve tried everything under the digital sun before. You’ve fiddled, tweaked, and maybe even shed a tear in frustration. But hope springs eternal, and here’s how we made it happen.
Gathering the Elements: Before the Code Begins
Before we jump like giddy schoolchildren into the code, we’re gonna have a small chat about preparation. Make sure your Shopify store is in tip-top shape—backups ahoy! Also, you should be somewhat familiar with your store's theme.liquid
and main-product.liquid
files, or their equivalents, because that's where our magic will be happening.
Long ago—by "long ago," I mean last Tuesday—I almost forgot about SVGs. It's vital to have those color images for each swatch you crave. And sizes? The difference between small and medium should be no bigger than our ambition.
Cracking the Code: The Deep Dive
Alright, let’s roll up our sleeves. We’ve got some lines to type and swatches to magic into existence. Follow along with me, and we’ll have our code done faster than you can say “No more monthly fees” thrice while spinning.
1. Creating Swatches
Dive head-on into your theme editor. Navigate to Assets
and create a new file—custom-swatch.css
is catchy, right?
Here’s a little code to give the colors some space to breathe:
.swatch {
display: inline-block;
margin: 5px;
cursor: pointer;
}
.shape-square {
height: 30px;
width: 30px;
border: 1px solid #ccc;
}
Next, hop over to Snippets
and create swatch.liquid
. Paste this charming morsel:
{% assign swatch_colors = 'Red, Blue, Green, Yellow' | split: ', ' %}
<ul class="swatches">
{% for swatch_color in swatch_colors %}
<li class="swatch shape-square" style="background-color: {{ swatch_color | downcase }};"></li>
{% endfor %}
</ul>
This ensures our swatches are delightful li'l nuggets on the product and collection pages.
2. Adding Size Swatches
Within the same product.liquid
, insert this unique concoction:
{% assign sizes = 'S, M, L, XL, 2XL, 3XL, 4XL, 5XL' | split: ', ' %}
<ul class="size-swatches">
{% for size in sizes %}
<li class="swatch shape-square">{{ size }}</li>
{% endfor %}
</ul>
Remember to save! Forgetting to click "save" is like leaving the house without your keys. Don’t.
Reaping the Rewards: Successfully Swatched
Now traverse back to your page—refresh it, dance a little if inclined, or maybe sip a chai latte in sheer victory. Look at that, our colors and sizes stand proud and app-less! It wasn’t without determination, but we did it. We cast off that monthly shackle and proved resourcefulness wins the day.
Curtain Call: Swatch in Hand
There’s something almost poetic about gazing upon a website you crafted with your own two hands (and a keyboard). Just like squares of chocolate you savor slowly, enjoy the craft of coding. Whether you’re catering to couture customers or collegiate aficionados, those swatches are a testament to not just choices in color and size but to the skills we foster along the way.
Together, we've solved what seemed an insurmountable challenge. So, here’s to more hurdles and our shared future victories—armed with nothing more than creativity, a sprinkle of code, and the audacity to dare. Cheers, dear friends.