How to make looping in Qweb by adding a newline (line break)

Viewed 301

I have a Many2many field and would like to make a new line after each item. When trying with other separators like : ',', '/', ... that's work. The problem was only with '\n'. I even tried with ' '

Here is my code:

 <span t-esc="'\n'.join(map(lambda x: x.name, move.myfield_ids))"/> 

Any help, please ? What's wrong?

Thanks.

1 Answers

Spaces, tabs or line breaks (white spaces) are largely ignored, whitespace in between words is treated as a single character, and whitespace at the start and end of elements and outside elements is ignored.

Whitespace character processing can be summarized as follows:

  • All spaces and tabs immediately before and after a line break are ignored
  • All tab characters are handled as space characters
  • Line breaks are converted to spaces
  • Any space immediately following another space (even across two separate inline elements) is ignored
  • Sequences of spaces at the beginning and end of a line are removed

1. Use the CSS white-space property to set how white space inside an element is handled

Example: Using pre-wrap value

<span style="white-space: pre-wrap;" t-esc="'\n'.join(map(lambda x: x.name, move.myfield_ids))"/>  

2. You can get the same result using the raw directive, which behaves the same as esc but does not HTML-escape its output. It can be useful to display separately constructed markup (e.g. from functions) or already sanitized user-provided markup.

Example: Using <br/>

<span t-raw="'&lt;br/&gt;'.join(map(lambda x: x.name, move.myfield_ids))"/>
Related