Reader small image

You're reading from  Shopify Theme Customization with Liquid

Product typeBook
Published inOct 2021
PublisherPackt
ISBN-139781801813969
Edition1st Edition
Tools
Right arrow
Author (1)
Ivan Djordjevic
Ivan Djordjevic
author image
Ivan Djordjevic

Ivan Djordjevic comes from the small town of Prokuplje, Serbia. As a self-taught developer, he spent the first few years working on different projects, but only when he came in contact with Shopify and learned about Liquid that he found himself. In 2016, Ivan joined Shopify Experts under HeyCarson, where he moved to the lead developer position after a few months. Since joining the Shopify family, Ivan found his passion in sharing his knowledge with other developers and guiding them on their way to becoming a Shopify Expert.
Read more about Ivan Djordjevic

Right arrow

Controlling whitespace

In the previous sections, we learned how to use conditionals with variable data types to ensure that we always receive a correct value. However, even with our conditionals, the same values can be accompanied by some unwanted whitespaces:

Collection info:
{% if collection %}
  The collection's name is {{ collection.title }} !
{% endif %}

In the previous example, we have created a conditional that will return true if our collection object exists, ensuring that our message will not be incomplete. While our result looks correct, if we were to inspect the page, we would see that things aren't perfect:

Collection info:
  The collection's name is Winter Shoes !

As we can see from our previous example, we have successfully recovered the collection information. However, we can see a significant number of empty spaces around our message, which results from processing Liquid code. Even though not every Liquid code will output...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Shopify Theme Customization with Liquid
Published in: Oct 2021Publisher: PacktISBN-13: 9781801813969

Author (1)

author image
Ivan Djordjevic

Ivan Djordjevic comes from the small town of Prokuplje, Serbia. As a self-taught developer, he spent the first few years working on different projects, but only when he came in contact with Shopify and learned about Liquid that he found himself. In 2016, Ivan joined Shopify Experts under HeyCarson, where he moved to the lead developer position after a few months. Since joining the Shopify family, Ivan found his passion in sharing his knowledge with other developers and guiding them on their way to becoming a Shopify Expert.
Read more about Ivan Djordjevic