Skip to content

Question / issue with "spaceless" #115

@cblake777

Description

@cblake777

Hello,

I'm having some issues attempting to use spaceless.

I've been working with using {% include %} in a template and was running into some new line issues. In an attempt to resolve them I was trying to use the spaceless tag (as I had seen recommended in several places as a django solution), but I'm getting some odd (corrupted?) output when attempting to use it.

It doesn't matter if the content inside the spaceless tag is from an include statement or just regular text. The only time it could display readable text was when whatever was inside of spaceless contained something that looked like tags, for example "<div> baz bat </div>". The spacing doesn't seem to be modified and it i'm getting what appear to be unexpected results. In one test, I added some extra text before and after the tags, and the text after the closing tag within the template was chopped off (example below). The corrupted output is displayed slightly different each time I run the oneliner as well.

Main template (example):

This is a test: bin: {% spaceless %}{% include "components/bin_text.tpl" %} - baz: {% include "components/baz_text.tpl" %}{% endspaceless %} foo bar {% spaceless %} a b c d e {% endspaceless %}{% spaceless %} <div> baz foo   -     bar bat </div> {% endspaceless %}{% spaceless %} f g <div> baz bat </div> h i {% endspaceless %} j k l

perl oneliner:

perl -MDTL::Fast -E 'my $tpl = DTL::Fast::get_template( "test.tpl", dirs => ["/path/to/template"]); my $foo = { thingy => { bin => 1, baz => 1, bat => 3 }}; print $tpl->render($foo);'

Output (sometimes there's a newline before the first </div>, sometimes there is not):

This is a test: baz: ��@� � foo bar �W�
<div> baz foo   -    bar bat </div> f g <div> baz bat </div> j k l

Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions