Blade turns newline into <br>

I have this code located in a shortcode function:

$output .= \App\template('components.form-field.checkbox' , [
            'label' => '',
            'options'       => $options,
        ]);

the part of the template view where this data is used looks like:

        @foreach ($options as $option)
            <label class="checkbox-container">
                {{ ($option['label']) }}
                <input type="checkbox" class="field" value="{{ $option['value'] }}" data-name="{{ $option['name'] }}" name="{{ $option['name'] }}">
                <span class="checkbox"></span>
            </label>
            @endforeach

the compiled html looks like :

Producten_-_Alku

How can I prevent the br tags

{{ }} escapes the output, while {!! !!} outputs unescaped.
When the option label contains line breaks,somehow, these could be escaped to <br> (I guess).
It would be better though to keep using {{ }} and prevent the unnecessary white space in the first place (during label save on admin, maybe trim()?).

1 Like

unfortunately not the desired result. I did already try this. All the ‘<br>’ in the above screenshot are new lines in my IDE

Have you checked the line endings of all involved files? Are UNIX line endings used?
Also from the screenshot I see that you inspect the actual (parsed) DOM, not the source HTML (string).
Inspect the raw HTML source (Ctrl + u) for strange characters.

1 Like

Hi @strarsis,

I did solve the issue, it was the wpautop function. I did fix it with adding this to my functions.php

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

thanks for thinking along

This topic was automatically closed after 42 days. New replies are no longer allowed.