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's preventing canvas from working offline but functioning properly on the TRYIT platform?

I have created some canvas-related code that works perfectly on TRYIT editor, but it fails to work locally when I copied the code into a file and tried to run it. This code is designed to take an image, set the width and height of a canvas based on that i ...

Creating a JavaScript function for a custom timed traffic light sequence

Currently, I am facing a challenge with my high school project of creating a timed traffic light sequence using JavaScript for my upcoming exams. Unfortunately, I feel quite lost and unsure about how to proceed. My initial plan involves formatting the valu ...

I am unable to retrieve the local variable beyond the function

I'm having trouble accessing a local variable outside of a function even though I have initialized it before the function is called. <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jq ...

Is React failing to identify parameters?

working on my react project, I have an App component which is responsible for rendering multiple child components. Here's how it looks: App render() { return ( //JSX inside <BrowserRouter> <div> <Heade ...

Exploring the React component life cycle: Understanding the distinction between render and return, and what happens post-return

This question pertains to the concepts surrounding react component life cycles. Below is an example code snippet provided as a general reference. const Modal = ({ className, variant, width, withCloseIcon, isOpen: propsIsOpen, onClose: tellParen ...

Responsive CSS Dropdown Menu - Divided into Two Columns

After searching for solutions in the support resources and experimenting with various techniques, I am struggling to divide this CSS Dropdown menu into two columns. The nav list is long enough that it extends below the fold. Although the menu adapts respo ...

Tips for removing the y-axis line in ChartJs

How can I hide the y axis line in a bubble chart? I attempted to use the code snippet below but it did not work as expected. yAxes: [{ angleLines: { display: false } }] ...

Filtering JSON data by date range in React JS

I have a dataset with JSON data containing ISO dates, and my goal is to filter out entries based on the "date_created" field falling within a specific date range. The time component should be ignored in this comparison, and the original JSON data should re ...

Identifying Labels in ThreeJS

I have a simple Threejs code where I am experimenting with click events using Raycaster. By using the BOX geometry, I have created three cubes in my scene. Additionally, I have utilized CSS2DRenderer.js to add a label above one of the cubes. My goal is t ...

Preventing users from copying and pasting information from my form by implementing javascript restrictions

I'm looking for a solution to prevent users from copying and pasting in my form using JavaScript. I want to restrict the ability to paste or copy any content into the form. Any assistance would be greatly appreciated! ...

JQuery selector is successfully working while vanilla JavaScript is not functioning as expected

This problem is unique because I am experiencing issues with querySelector and querySelectorAll in my JavaScript code. While JQuery works fine, vanilla JS does not work as expected. I would appreciate any insights on why this might be happening. Thank you ...

Top method for directly converting SVG to JSX within a popular React component library

Currently, I am exploring the most effective method to directly import SVG images as JSX components into my React common component library. By "common component library," I am referring to a distinct package that houses shared components utilized by variou ...

Dividing a fixed string state according to an increment state and showcasing the state in a React component

I'm facing an issue with my code structure, which can be found here: CodeSandbox The problem lies within the useGenText() hook that generates words every nth second in a read-only format, meaning it cannot be modified. Additionally, there is the useL ...

How can I extract echoed information from PHP after submitting form data through jQuery Ajax?

I am looking to transfer a file from an input form to a php script using ajax and handle the response echoed by my php script. Here is my HTML form: <form id="fileUploadForm" method="POST" enctype="multipart/form-data"> <input name="fileToU ...

Output each element of an array in Vuejs2 with a line break between each

I am currently working with vuejs2 and have a select tag where a person is selected, with their address properties directly bound to the element. I need to display the address of the selected person. I attempted to use an array in order to print out the el ...

How to handle users with disabled Javascript? Considering redirection to alternate sites for users with script disabled?

I've dedicated today to strategizing the best approach for revamping our company's website, taking into consideration that less than 1% of web users have JavaScript disabled. Our management team strongly believes in ensuring that our website rem ...

Rails with Ajax: The destroy.js.erb file has been rendered successfully, but the specific div element identified by its id is not being successfully

Trying to implement a feature where users can click an unfollow button to end a friendship using ajax. However, the div does not disappear even though the console indicates that destroy.js.erb was rendered successfully. The expected outcome is for the reco ...

Employ a class function within router.get

I'm a beginner with node.js and I'm running into an issue when trying to use a class method in the router.get callback function. Can someone assist me with this problem? Route.get() is expecting a callback function but received a [object object] ...

Tips for customizing the appearance of an HTML dropdown menu

Here is the code snippet: <select name="xyz" id="abc"> <option value="x">10/Page</option> <option value="y">20/Page</option> <option value="z">30/Pa ...

Ensuring proper input with JavaScript form validation

Currently, I am working on implementing a basic form validation feature, but it is not functioning as intended. The desired behavior is for the field border to change color to green or red based on its validity, while displaying text indicating whether t ...