0

I've correctly set up express handlebars with the following directory structure:

views/
    layouts/
    partials/

user-search-partial.html (stored in views > partials)

<div id="user-search">

    <h1>Search Users</h1>

</div>

render block

res.render('partials/site-user-search', { layout: false });

Using Angular on the frontend that makes various xhr requests for partial views, I need to render just the partial above without any layout/view wrapper. I managed to achieve this by adding the 'partials' directory name in the res.render view name but it feels like a hack. I was wondering, is there another way of loading just a partial, perhaps by adding a partials declaration to the locals/options object (second res.render parameter)?

K Scandrett
  • 16,390
  • 4
  • 40
  • 65
I am me
  • 131
  • 2
  • 12
  • Just create a directive and use the replace property, [which is, unfortunately, deprecated](http://stackoverflow.com/questions/24194972/why-is-replace-deprecated-in-angularjs) – Amy Blankenship Apr 03 '17 at 21:28
  • @amy-blankenship Sorry Amy, this question concerns express handlebars on the server side and not Angular on the frontend. Am I missing something? – I am me Apr 03 '17 at 21:31
  • Sorry, why did you tag it angularjs if you're not really using angularjs as angularjs? – Amy Blankenship Apr 03 '17 at 21:47
  • @amy-blankenship To give context to the issue at hand, and being part of the MEAN stack I imagined an Angular + Express developer may have encountered this scenario. – I am me Apr 03 '17 at 22:05

1 Answers1

0

You can use if condition. For example in default layout.hbs:

{{#if layout}}<!DOCTYPE html>
<html>
  <head>
    <title>{{title}}</title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    {{/if}}{{{body}}}{{#if layout}}
  </body>
</html>{{/if}}
stdob--
  • 28,222
  • 5
  • 58
  • 73