【问题标题】:E.js Template: Unexpected token 'else'E.js 模板:意外的标记 'else'
【发布时间】:2021-02-14 18:13:08
【问题描述】:

我目前正在用 e.js 和 Express 快速组合网站。

但是,在学习使用标签后,我在使用 e.js 标签中的 if-else 语句时遇到了一些问题。

我的 if 语句工作得很好,但是当我添加 else 语句时就会出现问题。

(仅供参考,此代码发生在部分代码中)

完整文件

<!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>

我得到的完整错误如下:

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.

如果有人能就如何解决此问题向我提供任何说明,那就太好了!

提前致谢。

【问题讨论】:

    标签: javascript html css express ejs


    【解决方案1】:

    这应该适合你。结尾的“if”括号和“else”语句应该在同一行。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      • 2017-01-19
      • 2014-08-30
      相关资源
      最近更新 更多