将条件EJS转换为条件HBS

时间:2019-05-30 18:55:20

标签: handlebars.js ejs

此EJS代码将图像发送到MongoDB。我需要将EJS代码转换为HBS,但是我的代码无法正常工作

EJS运作良好(请参见图片https://drive.google.com/file/d/1PVPYdF4Zh8jp2fPpKwK1ZxPCEEIN8IRz/view?usp=sharing

禁止运行(请参见图片https://drive.google.com/file/d/1gGV6CSikf3mW5mXAk9JOJJOLI2epoUZh/view?usp=sharing

tks!


<body>
  <div class="container">
    <div class="row">
      <div class="col-md-6 m-auto">
        <h1 class="text-center display-4 my-4">Mongo File Uploads</h1>
        <form action="/upload" method="POST" enctype="multipart/form-data">
          <div class="custom-file mb-3">
            <input type="file" name="file" id="file" class="custom-file-input">
            <label for="file" class="custom-file-label">Choose File</label>
          </div>
          <input type="submit" value="Submit" class="btn btn-primary btn-block">
        </form>
        <hr>
        <% if(files){ %>
          <% files.forEach(function(file) { %>
            <div class="card card-body mb-3">
              <% if(file.isImage) { %>
                <img src="image/<%= file.filename %>" alt="">
                <% } else { %>
                  <%= file.filename %>
                    <% } %>
                      <form method="POST" action="/files/<%= file._id %>?_method=DELETE">
                        <button class="btn btn-danger btn-block mt-4">Delete</button>
                      </form>
            </div>
            <% }) %>
              <% } else { %>
                <p>No files to show</p>
                <% } %>
      </div>
    </div>
  </div>



<body>
<div class="container">
  <div class="row">
    <div class="col-md-6 m-auto">
      <h1 class="text-center display-4 my-4">Mongo File Uploads</h1>
      <form action="/upload" method="POST" enctype="multipart/form-data">
        <div class="custom-file mb-3">
          <input type="file" name="file" id="file" class="custom-file-input">
          <label for="file" class="custom-file-label">Choose File</label>
        </div>
        <input type="submit" value="Submit" class="btn btn-primary btn-block">
      </form>
      <hr>
    {{#if files}}
      {{#each files}}
          <div class="card card-body mb-3">
            {{#if file.isImage}}
                <img src="image/{{file.filename}}" alt="">

                {{else}}
                    {{file.filename}}
                <form method="POST" action="/files/{{file._id}}?_method=DELETE">
                  <button class="btn btn-danger btn-block mt-4">Delete</button>
                </form>
              </div>
          {{/if}}
      {{/each}}
    {{/if}}
    </div>
  </div>
</div>

0 个答案:

没有答案