Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Django template without newline

My main.html template contains the following code:

<p>{% include "pouac.html" %}{% include "pouac.html" %}</p>

The pouac.html file contains a single line:

<span>pouac</span>

The main.html template produces the following two lines of html code:

<span>pouac</span>
<span>pouac</span>

The nasty side effect is that this code produces some white space between the two "pouac" words (e.g: "word1" and "word2" are separated by a whitespace in http://jsfiddle.net/regisb/CBtaz/)

In order to get rid of this whitespace, I would like to render a Django template without adding an extranuous line break. How can I do that?

like image 507
Régis B. Avatar asked Dec 04 '22 10:12

Régis B.


1 Answers

You can use the spaceless [1] template tag.

{% spaceless %}{% include "pouac.html" %}{% include "pouac.html" %}{% endspaceless %}

[1] https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#spaceless

like image 58
ojii Avatar answered Dec 06 '22 23:12

ojii