johnknoop / vscode-handlebars-preview

Preview Handlebars templates in VS Code
MIT License
16 stars 10 forks source link

Error rendering handlebars template #44

Closed alejo-monkee closed 2 years ago

alejo-monkee commented 2 years ago

Hi. I was learning handlerbars then I tried your plugin.

First, I cloned this simple hbs example ( git@github.com:jkasun/sa-handle-bars.git ). It runs as expected in http://localhost:3000/ with $ node app.js.

But then, when I want to preview a .hbs file with your plugin, I always get

Error rendering handlebars template : {"message":"The partial header could not be found","name":"Error"}

Where is the problem? Thanks in advance!

johnknoop commented 2 years ago

It looks like you reder to a partial called "header" that can't be found. Do you have such a partial?

johnknoop commented 2 years ago

Note that this extension will only look for partials in the "./partials" subfolder.

alejo-monkee commented 2 years ago

@johnknoop Hey, thanks for answering!

Yes, it is there (Sorry, before I posted the wrong link: https://github.com/jkasun/sa-handle-bars)

johnknoop commented 2 years ago

Currenty, the extension only looks for a "partials" folder directly under the root folder, so in this case you need to open the "views" folder in VS code.

alejo-monkee commented 2 years ago

Thanks for the hint, @johnknoop. Sadly, that doesn't work either. When I try to preview view/home.hbs, I get the same error:

Error rendering handlebars template: {"message":"The partial header could not be found","name":"Error"}

But it should work, right? Does it work for you?

johnknoop commented 2 years ago

I believe I lied to you by mistake. The extension doesn't treat the partials folder any differently than other folders. Therefor, you need to prefix the name of the partial, like this:

image

johnknoop commented 2 years ago

I know that this differs from how for example express-handlebars works, where the "partials" folder is magic in the sense that any templates in that folder are registered as the filename only.

Does the workaround work for you? Otherwise, I could try and ship an update within a week or so that registers all templates under /partials directly.

alejo-monkee commented 2 years ago

It would work to preview but sadly would also break my code. Not really convenient for me because I have 35+ templates to edit, each on its own folder.

An update will be utmost appreciated.

johnknoop commented 2 years ago

I'll try to find some time for this. In the meantime, you should be able to work around it by changing the partialsDir folder in your express code from views/partials to just views. I haven't tried this myself, but it should work from what I understand when reading their docs.

johnknoop commented 2 years ago

@alejo-monkee Sorry for the long wait. It completely escaped me, but I've now added a reminder for myself to address this.

Did you manage to work around it or are you still waiting for this?

johnknoop commented 2 years ago

@alejo-monkee Fixed and published!

All templates located in a folder called either "Partials" or "partials" directly under the workspace root will now be registered under the filename directly.