Search code examples
jekyllliquidstatic-site

Jekyll is putting spaces around my id names making them useless


Jeykll is outputting catergory_name and tag_name variables with spaces around it, which is destroying my IDs used with the variable.

Has anyone seen this before?

<a class="link" href="{{ site.baseurl }}/categories/#{{category_name}}">{{category_name}}</a>

The output on website with a category name of pizza. Notice the category name (pizza) in the URL has a space before and after.

<a class="link" href="/categories/# pizza ">pizza</a>

Solution

  • I am unable to reproduce the leading whitespace in my test environment so the best I can do is suggest a workaround.

    You can try to trim all leading and trailing whitespaces in your {{category_name}} Liquid variable with strip [1].

    {{ category_name | strip }}
    

    [1] https://shopify.github.io/liquid/filters/strip/