The E.js Template encountered an error with an unexpected token "else"

I am in the process of creating a website quickly using e.js & Express.

However, I am encountering some problems when trying to use an if-else statement within e.js tags.

The if statement works fine, but as soon as I add an else statement, things start to go wrong.

(Just so you know, this code is part of a partial)

Full file

<!DOCTYPE html>
<html>
<head>

    <meta charset="UTF-8">
    <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@500&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Oleo+Script+Swash+Caps:wght@700&display=swap" rel="stylesheet">
    <link rel="shortcut icon" href="images/CaffLogWhite.png">
</head>


<header>
    <nav>
        <div class="nav-wrapper">
            <a href="/">
                <img class="nav-logo" src="images/CaffLogBlack.png" alt="CaffeinatedLogo" style="width:95px;height:95px;">
                <t style="font-size: 36px">
                    <b>Caffeinated</b>
                </t>
            </a>
            <ul id="nav-mobile" class="right hide-on-med-and-down">
                <li><a href="/ToS">Terms of Service</a></li>
                <li><a href="/faq">FAQ</a></li>

                <% if (user) { %>
                    <a href="/auth">
                        <button class="btn">
                            <span>Login with Discord</span>
                        </button>
                    </a>
                <% } %>
                <% else { %>

                <% } %>
            </ul>
        </div>

        <hr>
    </nav>

</header>

<style>
    nav t {
        float: left;
        position: relative;
        color: #323232;
        font-family: 'Quicksand', sans-serif;
        margin-top: 20px;
        font-family: 'Oleo Script Swash Caps', cursive;
    }

    nav {
        position: fixed;
        width: 100%;
        text-decoration: none;
        display: inline-block;
        font-size: 28px;

    }
    nav ul {
        display: table;
        margin: 0 auto;
        width: 60%;
        text-decoration: none;
        list-style-type: none;
        color: #323232;
        overflow: auto;
        height: 20px;
    }

    nav ul li a {
        text-decoration: none;
        font-family: 'Quicksand', sans-serif;
    }

    .nav-logo {
        float: left;
    }

    nav ul li {
        color: #323232;
        display: inline-block;
        margin-right: 40px;
        margin-top: 28px;
        list-style-type: none;
        font-size: 24px;
    }

    nav ul button {
        display: inline-block;
        float: right;
        background: #7289DA;
        color: white;
        text-decoration: none;
        list-style-type: none;
        font-family: 'Quicksand', sans-serif;
        font-size: 18px;
        width:103px;
        height:57px;
        border-radius: 8px;
        margin-right: -142px;
    }

    nav ul button:hover {
        background: #3857c7;
    }

</style>

</html>

The error message that appears is:

E:\dev\CaffeinatedWebsite\views\profile.ejs:10 8| </title> 9| <link rel='stylesheet' href='/stylesheets/style.css' /> >> 10| <%- include('./partials/header.ejs', { user } ) %> 11| </head> 12| 13| <div class="welcome-message-caff"> Unexpected token 'else' in E:\dev\CaffeinatedWebsite\views\partials\header.ejs while compiling ejs If the above error is not helpful, you may want to try EJS-Lint: https://github.com/RyanZim/EJS-Lint Or, if you meant to create an async function, pass async: true as an option.

If anyone has any insights on how to resolve this issue, I would greatly appreciate it!

Thank you in advance.

Answer №1

Here is a suggestion that may be helpful to you. It's recommended to keep the closing "if" bracket and the "else" statement on the same line for better readability.

<div class="menu-wrapper">
            <a href="/">
                <img class="menu-logo" src="images/CafeLogo.png" alt="CafeLogo" style="width:95px;height:95px;">
                <t style="font-size: 36px">
                    <b>Cafe Name</b>
                </t>
            </a>
            <ul id="nav-menu" class="right hide-on-med-and-down">
                <li><a href="/privacy-policy">Privacy Policy</a></li>
                <li><a href="/contact-us">Contact Us</a></li>

                <% if (customer) { %>
                    <a href="/login">
                        <button class="btn-login">
                            <span>Sign In with Google</span>
                        </button>
                    </a>
                <% }else{ %>

                <% } %>
            </ul>
        </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the most efficient way to organize these arrays?

I've been racking my brain trying to figure out a sorting logic for some arrays, but I'm stumped. Maybe you have an idea? Imagine we have an array of objects structured like this: let obj = {day:'2', month:'6', year:'19 ...

Showcase a sizable picture broken down into smaller sections

I am interested in creating a mapping application similar to Google Maps that can asynchronously load images from the backend. I am seeking guidance on where to begin and how to proceed in this endeavor. The ultimate goal is to have the image displayed w ...

Is window.getComputedStyle not functioning as anticipated?

Here is a function I created to determine the width and height of a text: function size_calculation(word,fontSize) { const div = document.body.appendChild(document.createElement('div')); div.textContent = word; div.style.cssText = ` fo ...

Aligning a div with absolute positioning vertically

There are two elements positioned side by side: an input field and a div. The div is absolutely positioned inside a relative element and placed to the right of the input. The input field has a fixed height, while the height of the div depends on its conte ...

Style the code presented within a div tag

I am in the process of creating a JavaScript-powered user interface that can generate code based on user interactions. While I have successfully implemented the code generation functionality and saved the generated code as a string, I am facing difficultie ...

Rebuilding Javascript Files in Your Project with Laravel 9

I recently set up a Laravel 9 project on my Mac and am looking to incorporate Vue components. The default Laravel installation includes a Vue component (js/Components/ExampleComponenets.vue) which I successfully displayed in a view file. Wanting to custom ...

The highlight_row function seems to be delayed, as it does not trigger on the initial onClick but works on subsequent clicks. How can I ensure it works properly right from the first click?

I developed an application using the Google JavaScript Maps API to calculate distances between addresses. I've encountered a bug where the row in the table is not highlighted on the first click, requiring a second click for the highlighting to take ef ...

The markerwithlabel feature failed to appear on the Google Map when using MeteorJS

I am encountering an issue with markerwithlabel not displaying on Google Maps in MeteorJS. I am using dburles:google-maps and markerwithlabel v1.1.9, but I can't seem to integrate them properly. Despite placing markerwithlabel.js in the public folder, ...

Retrieve the data from a Sequelize Promise without triggering its execution

Forgive me for asking, but I have a curious question. Imagine I have something as simple as this: let query = User.findAll({where: {name: 'something'}}) Is there a way to access the content of query? And when I say "content," I mean the part g ...

Uniform Image Sizes in Bootstrap Carousel (With One Exception)

I am encountering a JavaScript exception related to image size. I am trying to set a fixed size for the images in my carousel, allowing them to auto adjust or resize without concern for distortion or pixelation. I have experimented with max-width and widt ...

How can TypeScript rules be incorporated into a Next.js project without compromising next/core-web-vitals?

In my current NextJS project which is in typescript, I have the following configuration in my .eslintrc.json: { "extends": "next/core-web-vitals" } Now, I want to include additional typescript rules, such as enforcing the rule of n ...

Utilize filtering techniques on a nested system

After creating an Angular app to display a hierarchy, I am now attempting to add a text box on top of the hierarchy for data filtering purposes. Despite trying various filter examples, I have not achieved much success. My goal is to implement Angular bind ...

Retrieving text content from an HTML element with Jsoup for web page manipulation

My task involves extracting text content from a specific HTML element <span class="adr" style="float: none !important;"> <span class="street-address" style="float: none !important;">18, Jawaharlal Nehru Road, </span> ...

Is it necessary to bump the major version if I make updates to a react module that does not affect existing code functionality, but may cause Jest snapshot tests to break?

Imagine I am developing a module for a react component and currently working on a PR to introduce a new feature. Along with this new feature, I have also made changes to the component by refactoring it to eliminate certain internal parts that were previou ...

Choose a selection from the options provided

This is a sample for demonstration purposes. I am trying to display an alert with the message "HI" when I click on Reports using the id main_menu_reports. My attempted solution is shown below. <ul class="nav" id='main_root_menu'> & ...

Tips for resolving the trigger problem with onChange in the PinInput Component of chakra-ui

The PinInput Component's onChange event is not functioning properly with the value in Chakra-UI. This issue causes the focus to automatically shift to the next input even when the value hasn't changed. For instance, when attempting to set the st ...

Running express in your Electron application: A simplified guide

Running express within an electron app has been a success with the help of various repositories that I found, including: https://github.com/theallmightyjohnmanning/electron-express https://github.com/frankhale/electron-with-express However, I have been ...

When using WYSIWYG editors, be on the lookout for empty paragraphs and incorrect code in CSS, JavaScript, and

I am currently in the process of redesigning a website for a client. The site is already built using Joomla 1.7, but I am facing an issue with the articles section that was created by the client using a WYSIWYG editor. The problem lies in the messy code st ...

Increase the jQuery Array

After successfully initializing an Array, how can I add items to it? Is it through the push() method that I've heard about? I'm having trouble finding it... ...

I'm at a loss with this useState error, can't seem to figure

Could you please help me understand what is incorrect in this code snippet? import React, { useState } from 'react'; import UsrInput from '../component/UsrInput' import TodoItemList from '../component/TodoItemList' const ...