E.js 模板:意外的标记“else" [英] E.js Template: Unexpected token 'else'

查看:25
本文介绍了E.js 模板:意外的标记“else"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 e.js & 快速制作一个网站快递.

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

我的 if 语句工作正常,但是当我添加 else 语句时就会出现问题.

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

完整文件

<头><元字符集=UTF-8"><link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@500&display=swap"rel=样式表"><link href=https://fonts.googleapis.com/css2?family=Oleo+Script+Swash+Caps:wght@700&display=swap"rel=样式表"><link rel="快捷方式图标";href="images/CaffLogWhite.png"><标题><导航><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>含咖啡因的</b></t></a><ul id="nav-mobile";class =正确隐藏在中间和向下"><li><a href=/ToS">服务条款</a></li><li><a href=/faq">FAQ</a></li><% if (user) { %><a href="/auth"><button class="btn"><span>使用 Discord 登录</span></a><%}%><% else { %><%}%>

<小时></nav></标题><风格>导航{向左飘浮;位置:相对;颜色:#323232;字体系列:'流沙',无衬线;边距顶部:20px;font-family:'Oleo Script Swash Caps',草书;}导航{位置:固定;宽度:100%;文字装饰:无;显示:内联块;字体大小:28px;}导航{显示:表;边距:0 自动;宽度:60%;文字装饰:无;列表样式类型:无;颜色:#323232;溢出:自动;高度:20px;}nav ul li a {文字装饰:无;字体系列:'流沙',无衬线;}.nav-logo {向左飘浮;}nav ul li {颜色:#323232;显示:内联块;右边距:40px;边距顶部:28px;列表样式类型:无;字体大小:24px;}导航按钮 {显示:内联块;浮动:对;背景:#7289DA;白颜色;文字装饰:无;列表样式类型:无;字体系列:'流沙',无衬线;字体大小:18px;宽度:103px;高度:57px;边框半径:8px;边距右:-142px;}导航按钮:悬停{背景:#3857c7;}</风格></html>

我得到的完整错误如下:

E:\dev\CaffeinatedWebsite\views\profile.ejs:10 8|9|<link rel='stylesheet' href='/stylesheets/style.css'/>>>10|<%- include('./partials/header.ejs', { user } ) %>11|12|13|<div class="welcome-message-caff">编译 ejs 时 E:\dev\CaffeinatedWebsite\views\partials\header.ejs 中出现意外标记 'else' 如果上述错误没有帮助,您可能想尝试 EJS-Lint:https://github.com/RyanZim/EJS-Lint 或者,如果您打算创建异步函数,请将 async: true 作为选项传递.

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

提前致谢.

解决方案

这应该适合你.结尾如果"括号和其他"语句应该在同一行.

I'm currently making a quick throw together website with e.js & Express.

However, upon learning to use tags I'm having some issues with using an if-else statement within e.js tags.

I'm my if statement works just fine, however when I add an else statement is when problems arise.

(Just FYI this code takes place within 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 full error I get is the following:

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 anybody could provide me any clarity on how to fix this issue, that would be great!

Thanks in advance.

解决方案

This should work for you. The ending "if" bracket and the "else" statement should be on the same line.

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

这篇关于E.js 模板:意外的标记“else"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆