loop line returns in a string? is this possible in template?

Is there a way in a template to loop line returns of a string?


template_string = “test

{% for line in template_string|loopLineReturn %}
  <p class="something something">{{line}}</p>
{% endfor %}

so output would be:

  <p class="something something">test</p>
  <p class="something something">test2</p>
  <p class="something something">test3</p>

is this possible?

Are you saying that you want to split a string by newline characters, such that you create a list of lines? If so, that’s something you would typically do in the view using the Python split function. You can then pass that list to the rendering engine in the context and iterate over it in your template.