if if pug语句

发布于 2025-02-01 09:42:35 字数 269 浏览 3 评论 0原文

我试图弄清楚如何进行内联如果语句:

div(class="social-text").
  #[b #{share.title}] #{share.bodyText}

在上面的代码中,share.title = undefined。如果是,我不想呈现< b></b>在结果html中标记,但无法弄清楚该如何工作在哈巴狗中。

I'm trying to figure out how to do an inline if statement:

div(class="social-text").
  #[b #{share.title}] #{share.bodyText}

In the code above it's possible that share.title=undefined. In case it is, I don't want to render a <b></b> tag in the resulting html but can't figure out how that works in pug.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫雪独思 2025-02-08 09:42:35

如果您不使用 block标签语法初始div之后。您可以这样写,使用标准条件 piped text

div.social-text
  if (share.title !== undefined)
    b #{share.title}
  |  #{share.bodyText}

This is simpler to write if you don't use the block in a tag syntax after the initial div. You could write it like this instead, using a standard conditional and piped text:

div.social-text
  if (share.title !== undefined)
    b #{share.title}
  |  #{share.bodyText}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文