【问题标题】:How can I display just a part of a string with pug/jade? [closed]如何使用 pug/jade 仅显示字符串的一部分? [关闭]
【发布时间】:2020-09-25 12:24:04
【问题描述】:

我想显示一个包含 250 个字符的文本。 p #{description} // display all the description 我如何在哈巴狗中做到这一点?

我尝试使用 substr 或 length 但它不起作用。

感谢您的帮助

【问题讨论】:

    标签: pug substr


    【解决方案1】:

    substr() 等 JavaScript 方法可以在 Pug 模板中轻松使用。你提到尝试substr() 但没有成功。你的尝试是这样的吗?

    p #{description.substr(0,250)}
    

    这应该使用description 字符串的前250 个字符创建一个<p>,前提是它存在并且是一个字符串。

    【讨论】:

    • 谢谢!我忘了括号中的“0”...
    猜你喜欢
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 2015-07-08
    • 2020-11-16
    • 2017-06-26
    相关资源
    最近更新 更多