Search code examples
textsplitjinja2

How to add two spaces after split?


On my code:

params: 
  "- key: fruits|value: apples, - key: travel_by|value: truck "

{% for elements in params.split(",") %}
{% for line in elements.split("|") %}
{{ line }}
{% endfor %}
{% endfor %}

I have this undesired result:

- key: fruits

value: apples



- key: travel_by

value: truck

Because I search the method to add 2 spaces " " before "value:..." after the split.


Solution

  • I found:

    I added 2 spaces after "|" on the data structure.

    params: 
      "- key: fruits|  value: apples, - key: travel_by|value: truck "
    

    With this, the second split cut the phrase with the "|" synbol in two parts and the second part start with 2 spaces for the correct identation.