简体   繁体   中英

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>
<!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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM