New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Native way to collapse whitespace #1519

MerlinBB opened this Issue Jul 23, 2017 · 2 comments


None yet
3 participants

MerlinBB commented Jul 23, 2017

Hey, not sure if this is a bug, feature request or I've just misunderstood the docs but here goes....

Expected behaviour

Using trim on a replicator or asset field would generate HTML with no whitespace.

Actual behaviour

HTML has whitespace.

Steps to reproduce

{{ gallery | trim }}
        {{ assets:image | trim }}
        <img src="{{ glide:id width="400" height="200" }}" alt="{{ description }}" class="gallery-tile">
        {{ /assets:image }}
{{ /gallery }}

The intention is that the above will yield the same output as the below, but this is not the case.

{{ gallery }}{{ assets:image }}<img src="{{ glide:id width="400" height="200" }}" alt="{{ description }}" class="gallery-tile">{{ /assets:image }}{{ /gallery }}

Server Details

Operating System: MacOS 10.12.5

Web Server: MAMP Pro

PHP Version: 7.0.15

Statamic Version: 2.5.11

Updated from an older Statamic or fresh install: Updated

List of installed addons: CookieConsent, Spock

Use Case

This is particularly useful when relying on display:inline-block; for layout as white space is taken into account. Example styling:

.gallery-tile {
    width: 33.333%;
    margin: 0;
    display: inline-block;
    vertical-align: top;

Being able to trim blocks of code like this would allow you to author code in a more readable format.


This comment has been minimized.


jasonvarga commented Jul 23, 2017

Hey there, a few things to note:

  1. To apply a modifier to an array (tag pair), you should use the parameter syntax. eg. {{ gallery trim="true" }} {{ /gallery }}
    ...or use the pipe syntax on the closing tag, eg. {{ gallery | trim }} {{ /gallery | trim }} (but that's lame, so don't do that).
  2. The trim modifier in your snippet is applying to the value of gallery, not the contents of the tag pair.

What you're probably looking for is another tag that wraps the whole thing, which strips out line breaks.

Here's one:


This comment has been minimized.

MerlinBB commented Jul 28, 2017

Hey Jason,

Thanks for getting back to me (and sorry for slow reply)... Cool the spaceless addon does the job perfect. I'd +1 the idea of having this built in as an antlers modifier in future though :)

@jasonvarga jasonvarga changed the title from trim on replicator and assets to FR: Native way to collapse whitespace Jul 28, 2017

@jackmcdade jackmcdade closed this Feb 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment