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

半腔热情 提交于 2020-01-25 07:58:08

问题


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 }}


回答1:


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>



回答2:


I'm not sure but try this

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


来源:https://stackoverflow.com/questions/59741391/how-to-make-the-address-code-on-one-line-with-twig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!