I’m writing form data into a file and an email by using the following twig:
{%- macro render_field(form, fields, scope) %}
{%- import _self as self %}
{%- for index, field in fields %}
{%- set show_field = attribute(field, "input@") ?? field.store ?? true %}
{%- if field.fields %}
{%- if field.type == "section" %}
{{- "\r\n" ~ field.title|replace({' *': ''}) ~ "\r\n" ~}}
{%- endif %}
{%- set new_scope = field.nest_id ? scope ~ field.name ~ '.' : scope %}
{{- self.render_field(form, field.fields, new_scope) }}
{%- else %}
{%- if show_field %}
{%- set value = form.value(scope ~ (field.name ?? index)) %}
{%- if value %}
{%- if field.label %}{{- field.label|t|e }}: {% endif %}
{{- string(value is iterable ? value|json_encode : value) ~ "\r\n" }}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endmacro %}
{%- import _self as macro %}
{%- autoescape false %}
{{- macro.render_field(form, form.fields, '') }}
{%- endautoescape %}
It works fine for the file, but in the email there are no new lines, but only spaghetti text. I already tried adding <br>
and <br />
but that didn’t work. It only led to <br>
and <br />
in the email and <
/ >
in the file.
What am I doing wrong?