jquery-tmpl icon indicating copy to clipboard operation
jquery-tmpl copied to clipboard

Markup option to remove space before and after

Open darobin opened this issue 14 years ago • 4 comments

In most templating systems there is a specific syntax that makes it possible to remove white space before and/or after a template instruction. This is very useful in order to make it possible for developers to indent their code meaningfully without incurring the cost of useless white space creeping in. For instance:

{{each(i, item) stuff}}
    {{if item.foo}}
        blah
    {{else}}
        urgh
    {{/if}}
{{/each}}: those are the results.

This will add a lot of white space that may prove problematic. Notably, the ":" right after {{/each}} is likely to end up with undesired space before it.

In several other templating languages (e.g. TT) this is handled with the addition of an optional - sign at the beginning of the template instruction. So with that {{-if test}} would remove space before it, {{/if-}} would remove space after, and {{-/each-}} would remove space on both sides.

Right now I'm preprocessing my tmpl code in order to support this, but it would be nicer to have it built it.

darobin avatar May 24 '11 12:05 darobin

thats actually not common. but a good idea ;)

tobsn avatar Jun 24 '11 22:06 tobsn

I think that is must have feature. Using such thing a lot in Mako and Jinja2 python template engines.

Other way is something like this:

{{each(i, item) stuff}}{{if item.foo}}blah{{else}}urgh{{/if}}{{/each}}: those are the results.

but that is less readable

Evgenus avatar Jun 25 '11 15:06 Evgenus

I agree that this would be very valuable. My case (HTML tags that are built via a loop but that need to have no space between them) may be more common:

{{each(i, dir) result.pathComponents}}
    <a href="#${dir.query}" class="query ${result.type}">${dir.name}/</a>
{{/each}}

I'm building a breadcrumb-style navigation control and I want there to be no space between the path components (unless I decide to tweak the CSS later).

nylen avatar Jul 09 '11 02:07 nylen

Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.

rdworth avatar Oct 08 '11 06:10 rdworth