Using node.js and hexo log I want to add a function to the one of the ejs files like post-details.ejs:
<div class="post-date info-break-policy">
<i class="far fa-calendar-minus fa-fw"></i><%- __('publishDate') %>:
<%- getSomething() %>
</div>
the getSomething function is my custom function which I'm unable to find a solution to use it inside the ejs file ...
I created a plugin and I extend the helper as the documents of hexo said but I get an error which says cannot find getSomething function...
How can I simply use a custom function in ejs files ?
You need to customize your syntax.
<div class="post-date info-break-policy">
<i class="far fa-calendar-minus fa-fw"></i><%- __('publishDate') %>:
<% getSomething() %>
</div>
I think this should work.
Related
I am trying to display image based on the path I get from database
here's my code
<% cars.forEach(function(car) { %>
<div class="card">
<div class="img">
<img src="images/" +"<%=car.Img_path %>">
</div>
</div>
<% }); %>
I also tried <img src="images/<%=car.Img_path %>"> but not working.
Can Anyone suggest how to render image.
Thanks In Advance.
<img src="images/<%=car.Img_path %>"> works. My issue was i didn't included Img_path in car model.
whoever may get this type of issue make sure you have included that field in model otherwise you will have data in database for but you wont get it in your application
I have express-flash installed and working, but only after I refresh the page I was redirected to. My controllers are using flash like so
req.flash("info", "No changes were made.");
res.redirect("/admin/dashboard");
In the view, I am importing a partial that looks like this.
<% if(messages.info) { %>
<div class="modal-content flashModal" id="message-info">
<div class="header">
<span id="closeBtn">×</span>
</div>
<div class="modal-body">
<strong>
<%= messages.info %>
</strong>
</div>
</div>
<% } %>
Not exactly sure what is causing the message to appear only after I have refreshed. It looks like the redirect is happening before the flash message? The documentation seemed straight forward enough but doesn't cover an issue like this. Any help is appreciated.
https://www.npmjs.com/package/express-flash
Try to use render instead of redirect. See if it works.
res.render('dashboard);
i built up a nodejs app using express and ejs as template engine. i can show a list of articles in a page but i don't know how to show detail of article when i click on the item. using Angular 4 you can use components and inject componets on the same page showing details in one compement when you click the item in the other one. i was wondering if it is possible to achieve same goal with ejs
<div class="container">
<div class="row">
<div class="col-lg-4">
<% items.forEach(item){%>
<ul>
<li><%=item%></li>
</ul>
<% } %>
</div>
<div class="col-lg-8>[here details of article]</div>
</div>
</div>
This is similar to Jade - convert new lines to <br/> and keep the content encoded
so is there easy way to do the same in ejs:
<%- escape(foo).replace(/\n/g, '<br/>') %>
This could be possible by extracting escape method from ejs and assign to res.locals, but I'm looking for something more elegant if it's possible
I had a similar problem, when I had to display git commit message in my page. I had a look at how GitLab formats commit messages and found out that they use white-space: pre-wrap. https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
So in my .ejs file I use:
<div style="white-space: pre-wrap"><%= commit.body %></div>
You can escape html with <%= %>, along with the replace function you already have (assuming foo is a string).
<%= foo.replace(/\r\n/g, '<br/>')) %>
I want to produce output like <% name %> which is for Backbone.js template with EJS. I can use
<%- "<%= name %>" %>
to solve it, but I think it makes some trouble.
EJS has no way to escape open and close tags. You can specify another open and close tags like {{ and }} that not confused with another document content.