user12030855
user12030855

Reputation:

How to make the address code on one line with TWIG?

I have a TWIG code to display the address of a store.

Currently the address is rendered on 3 lines.

How to make the address code on one line ?

{{ store.address|render|trim|replace({'<br>': ' - '})|striptags|raw }}

enter image description here

Upvotes: 0

Views: 125

Answers (2)

DarkBee
DarkBee

Reputation: 15577

Your are outputting the address inside a <pre> tag. The white-space of the <pre> tag is set to pre by default. See here for more information about this.

So you have 2 options

  1. Replace the <pre> tag with a <div>

<div>
Lorem
        ipsum
            dolor
                sit
                    amet
</div>

  1. Overrule the white-space of the <pre> with css

pre.spaceless {
  white-space: normal;
}
<pre>
Lorem
    ipsum
        dolor
            sit
                amet
</pre>
<pre class="spaceless">
Lorem
    ipsum
        dolor
            sit
                amet
</pre>

Upvotes: 0

Mohamed ELKACHTOULI
Mohamed ELKACHTOULI

Reputation: 11

I'm not sure but try this

{{ store.address|render|trim|replace({'<br>': ' - ','\n':' ', '\r':' '})|striptags|raw }}

Upvotes: 0

Related Questions