qasdf7
qasdf7

Reputation: 63

include ejs with statement

I want to know if it's possible to include my header with ejs only if the user is loggin. I tried this:

<% if(connect) { %>
    <%- include('../partials/header-login'); %>
<%  } else { %>
    <%- include('../partials/header'); %>
<% } %>

Is someone having a solution ?

Upvotes: 0

Views: 68

Answers (1)

guilfer
guilfer

Reputation: 322

You are in the right track! From the docs:

Html template:

    <% if (user) { %>   <h2><%= user.name %></h2> <% } %>

Usage:

let template = ejs.compile(str, options);
template(data);
// => Rendered HTML string

ejs.render(str, data, options);
// => Rendered HTML string

ejs.renderFile(filename, data, options, function(err, str){
    // str => Rendered HTML string
});

You can see more details on the oficial documentation: https://ejs.co/#docs

Upvotes: 0

Related Questions