[英]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.