【问题标题】:If statement not working in pug如果语句在哈巴狗中不起作用
【发布时间】:2016-11-13 19:00:16
【问题描述】:

它一直显示警报...我的unless errors 出了什么问题?

我的路线

app.set('view engine', 'pug')

app.get('/', function (req, res) {
  res.render('index', { errors: false })
})

索引.pug

<!DOCTYPE html>
<html lang="nl">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <!--<link rel="icon" href="../../favicon.ico">-->

    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="signin.css" rel="stylesheet">
  </head>

  <body>

    <div class="container">
      unless errors
        .alert.alert-danger
          <strong>Oh snap!</strong> Change a few things up and try submitting again.

      <form class="form-signin" method="POST" action="/">
        <h2 class="form-signin-heading">Login om verder te gaan</h2>
        <label for="inputEmail" class="sr-only">Email adres</label>
        <input type="email" id="inputEmail" class="form-control" placeholder="Email adres" required autofocus>
        <label for="inputPassword" class="sr-only">Wachtwoord</label>
        <input type="password" id="inputPassword" class="form-control" placeholder="Wachtwoord" required>
        <div class="checkbox">
          <label>
            <input type="checkbox" value="remember-me"> Onthoudt mij
          </label>
        </div>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
      </form>

    </div> <!-- /container -->

    <script src="js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>

【问题讨论】:

  • 你不是说“如果有错误”吗?如果错误等于 false,“除非错误”将返回 true,它确实如此。 (我不认识哈巴狗,但这似乎是问题所在)

标签: node.js express pug


【解决方案1】:

Pug 使用缩进定义标签嵌套,没有任何标签打开或关闭:

doctype default 
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, shrink-to-fit=no")
        //- The above 3 meta tags *must* come first in the head; any other head content must come *after* these

        meta(name="description", content="")
        meta(name="author", content="")

        title Signin Template for Bootstrap
        link(rel="stylesheet", href="/css/bootstrap.min.css")
    body 
        div(class="container")
            - if errors
                .alert.alert-danger
                    strong Oh snap!
                    | Change a few things up and try submitting again.


            form(class="form-signin", method="POST", action="/")
                h2(class="form-signin-heading") Login:
                label(for="inputEmail", class="sr-only") Email address 
                input(type="email", id="inputEmail", class="form-control", placeholder="Email address", required autofocus)
                label(for="inputPassword", class="sr-only") Password
                input(type="password", id="inputPassword", class="form-control", required)
                div(class="checkbox")

并继续使用您的模板。

【讨论】:

    猜你喜欢
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多