【问题标题】:MEAN: Jade Template problems with conditional Meta TagsMEAN:条件元标记的 Jade 模板问题
【发布时间】:2014-12-30 16:43:07
【问题描述】:

我的翡翠布局中有以下内容

doctype html
html
head
  meta(charset='utf-8')
  meta(http-equiv='X-UA-Compatible', content='IE=edge')
  meta(name='viewport', content='width=device-width, initial-scale=1')
  if (pageDescription)
    meta(name='description', content=#{pageDescription})
  else
    meta(name='description', content='My description.')

但是这会产生“Express 500 语法错误”

 7| | if (pageDescription)

 8| |

 9| meta(name='description', content=#{pageDescription})

 10| |

 11| | else

 12| |

Q) 那么如何在我的模板 Head 中包含条件 Meta 标签?

【问题讨论】:

    标签: javascript node.js express pug mean-stack


    【解决方案1】:

    #{pageDescription} 只能在字符串中使用,例如"#{pageDescription}"。你可以这样做,或者直接传递值:

    meta(name='description', content=pageDescription)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 2013-03-20
      相关资源
      最近更新 更多