奇怪的ejs语法错误

时间:2017-03-04 06:59:28

标签: node.js express ejs

我是node.js的新手,并按照博客进行练习。但是当我来写博客时写的视图时。我遇到了一些奇怪的问题。

我将ejs作为express中的视图引擎和signup.ejs这样的

<%- include('header') %>
  <div class="ui grid">
  <div class="four wide column"></div>
  <div class="eight wide column">
   <form class="ui form segment" method="post" enctype="multipart/form-data">
    <div class="field required">
      <label>username</label>
      <input placeholder="username" type="text" name="name">
    </div>
    <div class="field required">
      <label>password</label>
      <input placeholder="password" type="password" name="password">
    </div>
    <div class="field required">
      <label>repeat password</label>
      <input placeholder="password" type="password" name="password">
    </div>
    <div class="field required">
      <label>sex</label>
      <select class="ui compact selection dropdown" name="gender">
        <option>m</option>
        <option>f</option>
        <option>x</option>
      </select>
    </div>
    <div class="field required">
      <label>avatar</label>
      <input type="file" name="avatar">
    </div>
    <div class="field required">
      <label>bio</label>
      <textarea name="bio" rows="5" v-model="user.bio"></textarea>
    </div>
  </form>
</div>

当我运行启动我的程序并在路径localhost:3000/signup中发送http请求时,我遇到了一些错误

SyntaxError: 
C:\Users\ct\Documents\mycode\nodestudy\formalblog\views\signup.ejs:1
 >> 1| <%- include('header') %>
    2| <div class="ui grid">
    3|   <div class="four wide column"></div>
    4|   <div class="eight wide column">

C:\Users\ct\Documents\mycode\nodestudy\formalblog\views\header.ejs:13
    11|   <body>
    12|     <%- include('components/nav') %>
 >> 13|     <%- include('components/nav-setting') %>
    14|     <%- include('components/notification') %>
Unexpected token if in         C:\Users\ct\Documents\mycode\nodestudy\formalblog\views\components\nav-setting.ejs while compiling ejs

我已检查文件路径以及node version is v7.2.0 for winejs version 2.5.6。我已经阅读了ejs的文档,但我不知道错误信息syntax error

更新:在nav-setting.ejs中显示内容,感谢您提醒我错误发生在哪里。

<div class="nav-setting">
  <div class="ui buttons">
    <div class="ui floating dropdown button">
      <i class="icon bars"></i>
    <div class="menu">
      <%= if (user) { %>
        <a class="item" href="/posts?author=<%= user._id %>">index</a>
        <div class="divider"></div>
         <a class="item" href="/posts/create">post</div>
         <a class="item" href="/signout">logout</a>
      <% } else { %>
         <a class="item" href="/signin">login</a>
         <a class="item" href="/signup">signup</a>
      <% } %>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

感谢那些对这个简单问题发表评论的人。

正如@ user268396和@Sangharsh所说,错误发生在Private Sub ApplicationDesignForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Connection() sql = "Select * From App" rs.Open(sql, Conn) While Not rs.EOF Dim item As ListViewItem = ListView1.Items.Add(rs.Fields("QRCode").Value) item.SubItems.Add(rs("Category").Value) item.SubItems.Add(rs("LastName").Value & ", " & rs("FirstName").Value & ", " & rs("MI").Value) item.SubItems.Add(rs("Gender").Value) item.SubItems.Add(rs("Address").Value) ListView1.FullRowSelect = True rs.MoveNext() End While 但不在nav-setting.ejs。在我检查signup.ejs后,我发现nav-setting.ejs在ejs中的语法错误。这里应该使用<%= if(user) {%>

<% if(user) { %><% %>都用于控制文档,但&lt; %%&gt;不会产生输出,所以它应该是正确的选择。

再次感谢您的回答。