How to remove the white space in Jekyll?
Asked Answered
O

5

5

In Jekyll templating, the Liquid tags used can generate a lot of white spaces. From Liquid's documents, use {{- -}} or {{% %}} can strip these white spaces.

But I got a Liquid syntax error when Jekyll building.

How to fix this problem or do you have any other methods to remove the white spaces?

Onomatology answered 27/11, 2016 at 15:6 Comment(2)
Are your templates in markdown or HTML. I find whitespace in HTML. Not so much in markdown.Carcassonne
It's a Liquid 4 feature. Jekyll still use Liquid 3.xChoroid
P
8

The {{- and {%- tags exist in the latest beta version of Liquid but Jekyll uses the latest stable version, which doesn't include those tags.

When there's a stable release of Liquid 4.0, the next release of Jekyll should include that update and thus those tags will be available to use on Jekyll sites.

Phoneme answered 27/11, 2016 at 17:0 Comment(1)
Yes, I wrote that page.Phoneme
A
4

Not sure if this is specific to Shopify, but you could try using the strip filter.

Input: {{ " So much room for activities! " | strip }}

Output: So much room for activities!

Aarika answered 15/8, 2018 at 17:31 Comment(1)
I can confirm this works, even in cases where the accepted answer doesntNombles
P
1

Jekyll v4 support using {{%- test_function -%}} and {{- variable -}} (details).

Otherwise the compression extension can be used.

Pastorate answered 23/7, 2020 at 7:44 Comment(0)
C
0

There is more than one Gem that will remove white space post build.

https://github.com/itafroma/jekyll-newline_collapse

https://github.com/stereobooster/html_press

Carcassonne answered 27/11, 2016 at 15:54 Comment(0)
V
0

I have had success using the remove method and specifying a blank space:

Input
{{ "Multiple words here" | remove: " " }}

Output
Multiplewordshere
Vacuous answered 19/5, 2017 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.