Open adamhollett opened 6 years ago
Ideally, tags would have a defined syntax grounded in some sort of consistent expression system. https://github.com/Shopify/liquid/issues/560 was an attempt at moving in that direction, but we never acted on it.
Without quote characters it's simply ambiguous; it would feel like an arbitrary choice to automatically #strip
the argument string.
OK, this is going to really show how junior I am, but what would happen if we just added a single optional space to the TagEnd regex?
I agree that #strip
ing the argument is probably a bad thing to default to, but I think it can be safely said that almost everyone who writes Liquid pads their variables and tags with spaces, so this extra space thing affects almost all custom tags.
@jonniesweb and I are working on some custom Liquid tags for a site that can divide a section of content into small chunks, each of which has a button you can click to view that section of content. We use it to separate different sets of instructions by device (so we don't have to show instructions for desktop, iOS, and Android at the same time). It's kind of like a tabbed carousel.
Our tag looks like this:
We pass a list of the device types as an argument and split it by commas.
The Liquid for Programmers wiki article says that arguments are passed to the tag "as a single string" which is true and works fine but this string includes the space before the tag termination pattern
%}
.So when my tag is written
{% sections Desktop, iOS, Android %}
, the argument that gets passed is'Desktop, iOS, Android '
, with a trailing space. Liquid is interpreting the single space following "Android" as part of the argument, and as a result I need to#strip
my argument string before I do anything with it. This seems like it shouldn't be happening.