简体   繁体   English

在其他页面上没有问题的 EJS 部分在一个页面上抛出 500 错误

[英]EJS partial that doesn't have problems on other pages throws 500 error on one page

I have a footer partial:我有一个页脚部分:

    </main>
        <footer class="pt-3 container">
                <p id="copyright" class="">
                    Copyright 2020 Robert Greenstreet
                </p>
            <!-- <script src="/javascripts/jquery-ui.min.js" ></script> -->
            <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
            <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
            <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
            <script src="/javascripts/script.js" type="text/javascript"></script>

            <% if(page && == 'ownerDashboard') { %>
                <script src="/javascripts/canvasRender.js"></script>
            <% } %>
            <script>

            </script>
        </footer>
    </body>
</html>

It loads fine on every other page, but on this one particular page it only loads if I comment out that small if block.它在每个其他页面上都可以正常加载,但是在这个特定页面上,只有在我注释掉那个小的if块时才会加载。 It's acting like I haven't passed in a page variable.这就像我没有传入page变量一样。 But even if I haven't, it should still work because of the && operator, right?但即使我没有,由于&&运算符,它应该仍然可以工作,对吧?

Here's the page EJS file:这是页面 EJS 文件:

<%- include("../partials/header") %>

<div class="container mt-5">
    <h1>
      <%= currentCompany.name %>
    </h1>
    <div class="row shadow-md">
      <div class="col">
        <table class="table">
          <!-- <thead>
            <tr>
              <th scope="col" class="border-0 bg-light"></th>
            </tr>
          </thead> -->
          <tbody>
            <tr>
              <td class="border-0 align-middle">
                Locations
              </td>
              <td class="border-0 align-middle">
                <%= currentCompany.locations.length %>
              </td>
            </tr>
            <tr>
              <td class="border-0 align-middle">
                Total Admins
              </td>
              <td class="border-0 align-middle">
                <% let totalAdmins = 0 %>
                <% for (let location of currentCompany.locations) { %>
                  <% totalAdmins += location.contacts.length %>
                <% } %>
                <%= totalAdmins %>
              </td>
            </tr>
            <tr>
              <td class="border-0 align-middle">
                Total Users
              </td>
              <td class="border-0 align-middle">
                <%= userCount %>
              </td>
            </tr>
            <tr>
              <td class="border-0 align-middle">
                Total Forms
              </td>
              <td class="border-0 align-middle">
                <% let totalForms = 0 %>
                <% for (let location of currentCompany.locations) { %>
                  <% totalForms += location.contacts.length %>
                <% } %>
                <%= totalForms %>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
</div>
<script>

</script>
<%- include("../partials/footer") %>

All of that loads just fine, it's just the footer partial所有这些都很好,它只是页脚部分

Here's the node render call (assuming the other items in the data object doesn't have any issues:这是节点render调用(假设data object 中的其他项目没有任何问题:

res.render('../views/company/profile.ejs', {currentCompany, userCount, page: 'companyProfile', title: 'Company Profile'})

Any ideas why it would it be giving me trouble here?有什么想法为什么会在这里给我带来麻烦? Like I said, it works fine on any other page.就像我说的,它在任何其他页面上都可以正常工作。 I've tried ejs-lint but I can't figure out how to get it to actually show me anything useful.我试过 ejs-lint 但我不知道如何让它真正向我展示任何有用的东西。 Their NPM readme is useless.他们的 NPM 自述文件没用。

There's an error in the second part of this code:这段代码的第二部分有一个错误:

if (page && == 'ownerDashboard')

Should be应该

if (page && someVariable == 'ownerDashboard')

or if that's the case:或者如果是这样的话:

if (page && page == 'ownerDashboard')

You only reach the error when page is defined, that's why the other pages load correctly.只有在定义页面时才会出现错误,这就是其他页面正确加载的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 这两行代码有什么不同,一个抛出错误,另一个不抛出? - How are these two lines of code different that one throws an error and the other doesn’t? Node / Express无法在500错误页面上加载CSS - Node/Express doesn't load CSS on 500 error page res.render()函数呈现ejs页面不会刷新UI,但是会调用ejs页面 - res.render() function rendering an ejs page doesn't refresh the UI, but the ejs page get called 我试图用 fetch 更新我的 ejs 页面,但它不起作用 - i tried to upate my ejs page with fetch but it doesn't work Ejs 部分页眉和页脚文件在一个文件中工作,而不在另一个文件中工作(同一目录级别) - Ejs partial header and footer file working in one file and not the other (same directory level) 我的主页上有图片幻灯片,但是当我 go 到其他页面时它会抛出错误 - I have an image slideshow on my homepage but when I go to other page it throws an error Rails Jquery不适用于其他页面 - Rails Jquery doesn't work on other pages 未捕获的引用错误 - 一个函数有效,另一个无效 - Uncaught Reference Error - one function works the other doesn't jQuery / JS错误在没有给定ID的页面上时 - jQuery/JS Error When on a page that doesn't have given ID 防止在PHP中缓存500个内部错误页面的问题 - Problems with preventing caching of 500 internal error page in php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM