简体   繁体   English

如何用TWIG在一行中制作地址码?

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

I have a TWIG code to display the address of a store.我有一个 TWIG 代码来显示商店的地址。

Currently the address is rendered on 3 lines.目前该地址呈现在 3 行上。

How to make the address code on one line ?如何在一行中制作地址代码?

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

在此处输入图片说明

Your are outputting the address inside a <pre> tag.您正在输出<pre>标签内的地址。 The white-space of the <pre> tag is set to pre by default. <pre>标签white-space默认设置为pre See here for more information about this.有关方面的更多信息,请参见此处

So you have 2 options所以你有2个选择

  1. Replace the <pre> tag with a <div><div>替换<pre>标签

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

  1. Overrule the white-space of the <pre> with csscss覆盖<pre> white-space

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

我不确定,但试试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM