【问题标题】:How to make the address code on one line with TWIG?如何用 TWIG 将地址码放在一行?
【发布时间】:2020-05-01 15:05:02
【问题描述】:

我有一个 TWIG 代码来显示商店的地址。

目前该地址以 3 行呈现。

如何使地址码在一行?

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

【问题讨论】:

    标签: html drupal twig drupal-8 drupal-commerce


    【解决方案1】:

    您正在输出&lt;pre&gt; 标记内的地址。 &lt;pre&gt; 标签的white-space 默认设置为pre。有关这方面的更多信息,请参阅 here

    所以你有两个选择

    1. &lt;pre&gt; 标记替换为&lt;div&gt;

    <div>
    Lorem
            ipsum
                dolor
                    sit
                        amet
    </div>
    1. css 覆盖&lt;pre&gt;white-space

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

    【讨论】:

      【解决方案2】:

      我不确定,但试试这个

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-09
        • 1970-01-01
        • 1970-01-01
        • 2019-07-03
        相关资源
        最近更新 更多