MrNobody
MrNobody

Reputation: 655

Nodejs Handlebars Dynamic Partials use

I have a main hbs, which is the main layer of my layouts. In this hbs I want to set one partial hbs based on if a person is logged in or not. If he's logged in I want to show a userInfo partial if he's not I want to see the >navbar partial for example. The main problem is, that if I render again this main giving a value to the userInfo partial (and checkig if the userInfo #eq value) the main page is rendered twice. How can I set and switch from between these two partials properly based on some value? Thank you very much.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ title }}</title>
<link href="/style.css"
rel="stylesheet"
type="text/css">
</head>
<body>
{{> userInfo}}
{{> nav}}
{{{ body }}}
</body>
</html>

Upvotes: 2

Views: 275

Answers (1)

TBK
TBK

Reputation: 71

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ title }}</title>
<link href="/style.css"
rel="stylesheet"
type="text/css">
</head>
<body>
{{#if userInfo}}
  {{> userInfo}}
{{else}}
   {{> nav}}
{{/if}}
{{{ body }}}
</body>
</html>

Can you try this one? I think this will help you. You can also add this condition to server side to make this decision.

Upvotes: 1

Related Questions