0
votes

I am working with a static web page, and I want to add partials in different html files.

Consider a src folder with javascript code, which is compiled later by browserify, in order to create a bundle.js file.

In src folder I created a views/partials/test path. The test folder contains a handlebars partial attempt.

test/template.js

const yo = require('yo-yo')
let template = yo`
  <script id='test' type='text/x-handlebars-template'>
    <div>
      <h1>This is a test sentence</h1>
    </div>
  </script>
`
module.exports = template

test/index.js

const handlebars = require('handlebars')
const template = require('./template')

$('body').append(template);
handlebars.registerPartial('Test', $('#test').html());

In main html file I added only bundle.js and added partial to body, in this case {{> Test}}, according to handlebars.registerPartial name.

However, in home view I got the syntax {{> Test}} as plain text, and not the test text: This is a test sentence. I tried to add handlebars cdn script directly to html file, but it shows the same result.

Am I missing something in javascript code or I need to add something to main html file?

I think that handlebars.registerPartial is not registering anything..

Any suggetions to solve this will be appreciated.

1

1 Answers

0
votes

Looks like a simple typo. Use Handlebars.registerPartial with a capital H.

Please let me know whether this helps.