I am displaying a series of icons and associated labels in an unordered list. Some of the icons should only be displayed when a user is in a specific set of user groups, so I am using a conditional. Without the conditional, the icon and label displays perfectly, but when I wrap it in a conditional, it seems to output an extra blank character which breaks my layout.

<li class="icon">
  <a href="/entry1">
    <img src="/assets/images/icon1.svg" alt="" />
    <div class="title">Entry 1</div>
{% if currentUser.isInGroup('admin') %}
<li class="icon">
  <a href="/entry2">
    <img src="/assets/images/icon2.svg" alt="" />
    <div class="title">Entry 2</div>
{% endif %}

Chrome Inspector shows two quotation marks separated by a blank line between the li.icon elements, which I think indicates one blank character. When I remove the conditional, these quotation marks and the blank line don't appear, and the layout looks correct.

If I collapse all the logic and HTML elements into one long line of characters with no spaces between them, this weird blank output still occurs. Wrapping the block in the {% spaceless %} tag doesn't seem to work either.

What might be causing this?


I pasted your HTML into TextMate with “Show Invisible Characters” enabled, and it shows that there are two “zero width no-break space” (U+FEFF) characters in there, at the end of these lines:

{% if currentUser.isInGroup('admin') %}

-- and --

{% endif %}

Here’s a screenshot:

Those characters tend to come from code that was copied from Google+, which likes to add them at the very end of each post.

Unfortunately, Sublime Text doesn’t show these types of characters; you need to use TextMate to see them.

  • Rrr! Why can't Google use visible Unicode characters like the rest of society! – Bryan Redeagle Jul 2 '14 at 17:08
  • Thanks Brandon, that was it. This Stack Exchange site is a great resource to have. – Alex H Jul 3 '14 at 8:18

I'd venture to guess that you have a BOM character in there somewhere. It's basically an invisible character that does nothing but cause trouble. One of these can show up from copying a chunk of code from somewhere else... quite often from the Google+ group.

The solution is generally to re-type your code by hand, and delete the original offending chunk of code. You can probably narrow down the specific line or two which may contain that BOM by deleting and checking your Chrome Inspector (like you already did to determine where the issue was coming from). Then you can just re-type the one or two lines which actually contain the BOM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.