Answer the question
In order to leave comments, you need to log in
Jade how to pass value from script to html element?
Good day to all. I can't figure out how to implement a construction from ejs in jade:
<% if (errors) {%>
<% errors.forEach(function (error) { %>
<%= __(error) %>
<% }) %>
<% } %>
<form role="form" action="/auth/local" method="post">
<input type="text" name="identifier" placeholder="Username or Email">
<input type="password" name="password" placeholder="Password">
<button type="submit">Sign in</button>
</form>
<% if (Object.keys(providers).length) {%>
<h4>You can also use one of these...</h4>
<% Object.keys(providers).forEach(function (key) { %>
<a href="/auth/<%= providers[key].slug %>" role="button"><%= providers[key].name %></a>
<% }) %>
<% } %>
<% скрипт %>
<%=ДАННЫЕ%>
<% продолжение скрипта %>
Answer the question
In order to leave comments, you need to log in
I asked myself, I answer. It happens.
A small explanation of where this code comes from. sails-generate-auth module for sails.js By default, sails.js uses the EJS templating engine and there are no problems with the above code. But it is worth generating a project for the jade template engine, as the module remains without a view and, accordingly, the functionality ceases to be available.
In order not to miss the little things, the view receives input data in the form of an errors array and a providers object:
res.view({
providers : providers
, errors : req.flash('error')
});
each error in errors
- var errorloc = __(error);
li #{errorloc}
form(role='form', action='/auth/local', method='post')
input(type='text', name='identifier', placeholder='Username or Email')
input(type='password', name='password', placeholder='Password')
button(type='submit') Sign in
-if (Object.keys(providers).length)
h4 You can also use one of these...
-var name = [];
-var slug = [];
-Object.keys(providers).forEach(function (key) { name.push(providers[key].name); slug.push(providers[key].slug) })
-for (var i = 0; i < name.length; i++)
a(href='/auth/#{slug[i]}', role='button') #{name[i]} 
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question