简体   繁体   中英

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. It's acting like I haven't passed in a page variable. But even if I haven't, it should still work because of the && operator, right?

Here's the page EJS file:

<%- 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:

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. Their NPM readme is useless.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM