I am working on an eWallet with Node Js and I have found a bug that I can't figure out what is the issue.
Here is the code for index.ejs:
`<!DOCTYPE html>
<html>
<head>
<meta charset="urf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Mr. Barasa Joel">
<meta name="description" content="eWallet - Free E-Wallet">
<meta name="keywords" content="E-Wallet, digital wallet, wallet">
<link rel="shortcut icon" href="img/favicon.ico">
<link rel="stylesheet" href="css/styles.css">
<title>E-Wallet</title>
</head>
<% if(page == 'home') { %><section class="image"><% } %>
<header class="header-columns header-filled header-mobile">
<img src="/img/icon-menu.png" alt="" height="24" id="mobile-menu">
<article class="header-columns header-left">
<img src="img/logo-full.png" alt="ewallet" height="40">
</article>
<article class="header-center">
<nav>
<ul class="header-columns menu">
<li>O eWallet</li>
<li>How it's working</li>
<li>Where will you pay</li>
</ul>
</nav>
</article>
<article class="header-columns header-right">
Create an account
Log in
</article>
</header>
<% if(page == 'home') { %></section><% } %>
<body <% if(page != 'home') { %>class="app-body gradient"<% } %>>
<% if(page == 'home') { %>
<%- include home %>
<% } else if(page == 'login') { %>
<%- include login %>
<% } else if(page == 'register') { %>
<%- include register %>
<% } %>
<footer class="footer-fixed-bottom">Copyright © 2023 Mr. Barasa Joel</footer>
<script src="/js/mobile-menu.js"></script>
</body>
</html>`
When I try to run the app on the browser, I get this error:
The error displayed is:
Error: missing ) after argument list in "Node\eWallet\views\index.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.
Error displayed
Related
I am just learning Rust's Rocket however when I compile the code, I get errors mentioned below. I am just trying to pass values to my templates variable from my rust file.
I have a src/main.rs file with following code:
#[macro_use] extern crate rocket;
use rocket_dyn_templates::{Template, context};
#[get("/")]
fn home() -> Template{
Template::render("index",context!{
title : "Hello, World",
logged_in : true,
user_name: "test"
})
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![home])
.attach(Template::fairing())
}
Inside templates/index.html.tera I following code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
</head>
<body>
<header>
<nav>
<div>
<h1>Test</h1>
</div>
<!-- Add navigation bar here !-->
<ul>
<li>
About
</li>
<li>
Edit Page
</li>
<li>
{% if logged_in %}
{{user_name}}
{% else %}
Login
</li>
</ul>
</nav>
</header>
<main>
<!-- Provide Title for your page here !-->
<h1>{{title}}</h1>
</main>
however when i compile the code i am greeted with following errors:
41 | </html>
| ^---
|
= expected tag or some content
Template initialization failed. Aborting launch.
Error: Rocket failed to launch due to failing fairings:
Templating
thread 'main' panicked at 'aborting due to fairing failure(s)',
I think you are forgetting to close some tags in the html/Tera code and that is why you are getting this error.
You are forgetting to close body, html, and the {% endif %} for the structure control
I modified the html code to something like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
</head>
<body>
<header>
<nav>
<div>
<h1>Test</h1>
</div>
<!-- Add navigation bar here !-->
<ul>
<li>
About
</li>
<li>
Edit Page
</li>
<li>
{% if logged_in %}
{{user_name}}
{% else %}
Login
{% endif %}
</li>
</ul>
</nav>
</header>
<main>
<!-- Provide Title for your page here !-->
<h1>{{title}}</h1>
</main>
</body>
</html>
and it works now
I want to make a queue system for to create pdf file. I created a node server and used Express framework. Also I used rabbitmq for the queue system. I set view engine ejs
app.set('view engine', 'ejs');
app.use(Express.static(__dirname + "/views"));
My folder structure is
consumers
--consumer_report.js
views
report.ejs
report
--environment.ejs
--consultans.ejs
--map.ejs
When a user wants to create a pdf, I redirect it to the queue. The queue is calculating some datas. After calculating I'm using render ejs file.
createReport(msg.user, msg.reportID, msg.type, msg.packetName, (err, data) => {
data.packet = msg.packetName;
let dirUrl = __dirname + "/../views/report.ejs";
let opts = {
async: true
}
ejs.renderFile(dirUrl, data, opts, (err, html) => {
if (err) return console.error(err);
console.log("html", html);
});
});
Report Ejs
<!DOCTYPE html>
<html lang="en" style="zoom:0.75;">
<head>
<meta charset="UTF-8">
<title>Report</title>
<link rel="stylesheet" href="<%= host %>/css/rp.css">
<script src="<%= host %>/js/jquery3.2.1.min.js"></script>
<script src="<%= host %>/js/highcharts.js"></script>
<script src="<%= host %>/js/rp.js"></script>
</head>
<body>
<% for(let i of index){brackets = i.i_page; title= i.name %>
<% if(brackets=="environment") {%> <%- include report/environment.ejs %> <% } %>
<% if(brackets=="consultant") {%> <%- include report/consultants.ejs %> <% } %>
<% if(brackets=="map") {%> <%- include report/map.ejs %> <% } %>
<% } %>
</body>
</html>
When render the ejs file I get this error
Error SyntaxError: missing ) after argument list in /home/aaa/Desktop/projects/report/consumers/../views/report.ejs while compiling ejs
I couldn't find the error. Where is my mistake?
you need to change include syntax to include(path), as per docs:
NOTE: Include preprocessor directives (<% include user/show %>) are
not supported in v3.0+.
https://github.com/mde/ejs
try this:
<!DOCTYPE html>
<html lang="en" style="zoom:0.75;">
<head>
<meta charset="UTF-8">
<title>Report</title>
<link rel="stylesheet" href="<%= host %>/css/rp.css">
<script src="<%= host %>/js/jquery3.2.1.min.js"></script>
<script src="<%= host %>/js/highcharts.js"></script>
<script src="<%= host %>/js/rp.js"></script>
</head>
<body>
<% for(let i of index){brackets = i.i_page; title= i.name %>
<% if(brackets=="environment") {%> <%- include('report/environment.ejs') %> <% } %>
<% if(brackets=="consultant") {%> <%- include('report/consultants.ejs') %> <% } %>
<% if(brackets=="map") {%> <%- include('report/map.ejs') %> <% } %>
<% } %>
</body>
</html>
<header class="main-header">
<nav class="main-header__nav">
<ul class="main-header__item-list">
<li class="main-header__item"><a class="<%= path === '/' ? 'active' : '' %>" href="/">Shop</a></li>
<li class="main-header__item"><a class="<%= path === '/admin/add-product' ? 'active' : '' %>" href="/admin/add-product">Add Product</a></li>
</ul>
</nav>
When I try to render the page in my node js application I am getting an error. Saying there is an error
I am not so used to writing ejs but when I remove the class="<%= path === '/' ? 'active' : '' %>" in the navigation.ejs it seems to work
Error Image
Use <%- include('RELATIVE/PATH/TO/FILE'); %> to embed an EJS partial in another file.
The hyphen <%- instead of just <% tells EJS to render raw HTML.
The path to the partial is relative to the current file.
and also use ; at end of include
Here is an example...
<!DOCTYPE html>
<html lang="en">
<head>
<%- include('../partials/head'); %>
</head>
<body class="container">
<header>
<%- include('../partials/header'); %>
</header>
<main>
<div class="jumbotron">
<h1>This is great</h1>
<p>Welcome to templating using EJS</p>
</div>
</main>
<footer>
<%- include('../partials/footer'); %>
</footer>
</body>
</html>
I have the following code in my header.ejs file for my Twitter card.
<head>
...
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="#DrDenverHBubble">
<meta name="twitter:creator" content="#DrDenverHBubble">
<meta name="twitter:title" content="<%= blog.title %>"></meta>
<meta name="twitter:image" content="<%= blog.image %>"></meta>
</head>
...
On my show.ejs page, my webpage display correctly and the Twitter card displays correctly as well on Twitter.
However, on my index.ejs page, I get the following error with the below code
ReferenceError: /home/ubuntu/workspace/drdenver/views/blogs/index.ejs:1
>> 1| <% include ../partials/header %>
2|
3|
4|
/home/ubuntu/workspace/drdenver/views/partials/header.ejs:16
14| <meta name="twitter:site" content="#DrDenverHBubble">
15| <meta name="twitter:creator" content="#DrDenverHBubble">
>> 16| <meta name="twitter:title" content="<%= blog.title %>"></meta>
17| <meta name="twitter:image" content="<%= blog.image %>"></meta>
18| </head>
19| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
blog is not defined
Here is the index.ejs code
<% include ../partials/header %>
<div id="blog-index" class="container">
<div class="row" style="display: flex; flex-wrap:wrap;">
<div class="col-lg-12">
<% if(noMatch !== null) { %>
<h4> <%= noMatch %> </h4>
<% } %>
</div>
<% blogs.forEach(function(blog){ %>
<div class="col-lg-12">
<div class="ui medium rounded items">
<div class="item">
<div class="image">
<img src="<%= blog.image %>">
</div>
<div class="content">
<a class="header" href="/blogs/<%= blog._id %>"><%=blog.title%></a>
<div class="meta">
<span><%= blog.created.toDateString() %></span>
</div>
<div class="extra">
<% if(blog.body && blog.body.length > 0) { %>
<p><%- blog.body.substring(0, 120) %> ... </p>
<% } %>
Read More
</div>
</div>
</div>
</div>
</div>
<% }) %>
</div>
...
I am a new coder, but I understand that I am not passing anything into the variable blog which is causing my error. My solution was to on the show page remove the <% include ../partials/header %> and insert the header code with twitter card code and in the header.ejs page remove the Twitter card code. Is there a more DRY way of coding this?
Thanks
Your problem is, You are including header.ejs file which needs blog data. But you are not passing blog data to it. Change your include line to following
<%- include('../partials/header', {blog: blog}); %>
i have signed up at inmobi,have made a banner ad and tried my best to get it working to no avail,seems like the ad div appears,but not the ad itself
here is my code.as yoU CAN see my property id provided by inmobi for ad has been entered.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="components/loader.js"></script>
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="components/loader.css">
<script src="js/cssua.min.js"></script>
<script src="js/inmobi.js"></script>
<script>
var inmobi_conf = {
siteid : "48a58302dd214f5ea5483a3f9d95a28e", // your Property ID
slot: 15,
test: true,
manual: true,
autoRefresh: 20,
targetWindow : "_top", // default "_top"
onError : function(code){
if(code == "nfr"){
console.log("Error getting the ads!");
}
if(code!=="nfr"){
console.log("getting the ads!");
}
}
};
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
console.log('device is ready');
showAds();
}
function showAds(){
var adsElement = document.getElementById('ads');
_inmobi.getNewAd(adsElement);
}
</script>
</head>
<body>
<div data-role="page">
<header data-role="header" data-position="fixed" data-theme="c">
<h1>Inmobi Client</h1>
</header>
<div data-role="content">
<img src="images/logo.png" width="300px">
</div>
<div data-role="header" data-position="fixed">
<div id="ads"></div>
</div>
</div>
</body>
</html>