Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.
This repository has been archived by the owner on May 9, 2023. It is now read-only.

FR: Native way to collapse whitespace #1519

Closed
MerlinMason opened this issue Jul 23, 2017 · 2 comments
Closed

FR: Native way to collapse whitespace #1519

MerlinMason opened this issue Jul 23, 2017 · 2 comments

Comments

@MerlinMason
Copy link

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.

@jasonvarga
Copy link
Member

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: https://github.com/marbles/statamic-spaceless

@MerlinMason
Copy link
Author

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 trim on replicator and assets FR: Native way to collapse whitespace Jul 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants