Could not find matching close tag for "<%"

Related searches

I am trying to access variables passed from the server to the client with ejs

My server file:

router.get('/', function (req, res, next) {
    res.render('chat', {user: req.user, message: null});
});

My client file:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" const="text/html;charset=UTF-8"/>
    <link href="http://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
    <title>Simple Chat App</title>
</head>

<body>
<header>
    <h1>Super Chat</h1>
</header>

<section>
    <div id="change_username">
        <input id="username" type="text"/>
        <button id="send_username" type="button">Change username</button>
    </div>
</section>

<section id="chatroom">
    <section id="feedback"></section>
</section>


<section id="input_zone">
    <input id="message" class="vertical-align" type="text"/>
    <button id="send_message" class="vertical-align" type="button">Send</button>
</section>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<script type="text/javascript">
    <% var user = <% user %> %>
    console.log(user);
</script>
<script src="chat.js"></script>
</body>
</html>

I get an error:

Could not find matching close tag for "<%".

How do I fix this?

<% var user = <% user %> %>

You can't nest <% %> blocks. You are either inside EJS mode or outside it. You can't go into Extra Deep EJS Mode.


Aside, you also can't just output a variable into client-side JS. You need to generate JavaScript source code from the variable. JSON.stringify is a good way to generate object, array and string literals from objects, arrays and strings.

<script>
    const user = <%- JSON.stringify(user); %>
    console.log(user);
</script>

Note that use of <%- to output without escaping for HTML.

Could not find matching close tag for "<%-". � Issue #389 � mde/ejs , Could not find matching close tag for "<%-". #389. Closed. axelrindle opened this issue on Jul 5, 2018 � 1 comment. Closed� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

The problem is here, you just have to replace the value of the user in the template.

 var user = "<%=user%>" // Please change this line 

Updated Code

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" const="text/html;charset=UTF-8"/>
    <link href="http://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
    <title>Simple Chat App</title>
</head>

<body>
<header>
    <h1>Super Chat</h1>
</header>

<section>
    <div id="change_username">
        <input id="username" type="text"/>
        <button id="send_username" type="button">Change username</button>
    </div>
</section>

<section id="chatroom">
    <section id="feedback"></section>
</section>


<section id="input_zone">
    <input id="message" class="vertical-align" type="text"/>
    <button id="send_message" class="vertical-align" type="button">Send</button>
</section>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<script type="text/javascript">
    var user = "<%= user %>" // problem is here 
    console.log(user);
</script>
<script src="chat.js"></script>
</body>
</html>

Error: Could not find matching close tag for "<%". Following a video , Error: Could not find matching close tag for "<%". Following a video 'Template Engines' by NetNinja, but don't know where I have went wrong. I got the error� Could not find matching close tag for "<%-". #389. axelrindle opened this issue Jul 5, 2018 · 1 comment Comments. Copy link Quote reply axelrindle commented Jul 5,

it says that it cannot find closing tag for your ejs template. you don't need the surrounding ejs template notation in script.

<script type="text/javascript">
var user = '<%= user %>'
console.log(user);
</script>

Try this. GOOD LUCK. :)

(not include) - node.js - html, causes: Could not find matching close tag for "<%". And, <% include ./layouts /%><%= layout %><%/header.ejs %> causes: Could not find the include file ". Crash when tags are not closed #121. Closed jadams41 opened this issue Nov 5, 2015 · 3 comments Error: Could not find matching close tag for "<%=".

Error: Could not find matching close tag for - Node JS, Error: Could not find matching close tag for "<%". Following a video 'Template Engines' by NetNinja, but don't know where I have went wrong. Some people, though, may want to close all their tags anyway. If you experience any problems, or have any suggestions, let me know. Before you start. Make sure your code is valid, or you could get unexpected results. The script assumes you have valid HTML5 code, but would like to make sure you didn't leave any tags, unintentionally, unclosed.

Could not find matching close tag for “<%”, Could not find matching close tag for “<%”. I am trying to access variables passed from the server to the client with ejs. My server file: router.get('/', function (req,� Empty elements. The plugin is able interpret some unclosed tags as self-closing. By default they correspond with HTML empty elements (img, meta, link, etc.). You can disable or extend them by changing highlight-matching-tag.noDefaultEmptyElements and/or highlight-matching-tag.customEmptyElements configuration options.

XML documentation parse error: Start tag <tag> doesn't have a matching end tag. XML comment will be ignored. The XML comment contains a start tag but does not contain a matching end tag.

Comments
  • replace <% var user = <% user %> %> with var user = <% user %>
  • @PHPNinja — That will fix the error, but still not work.
  • var user = <% user %> wont work. <% is for control flow. to Output a certain thing you have to use <%= user %> . equal sign after the percentage sign is necessary.
  • @WaleedShafiq — That does escaping for HTML. It isn't being output into HTML.
  • <%= performs HTML escaping, not JS escaping.
  • It gives the wrong output if (a) user is not a string or (b) user is a string containing a & or < and it breaks the script if it is a string which contains a '.