Skip to content

Override partial  #191

@mbalex99

Description

@mbalex99

Great library everyone! I have a problem where I occasionally want use a partial outside of the partials directory

Here's my express server code

app.engine('hbs', hbs.express4({
  defaultLayout: path.resolve(__dirname, "../views/layouts/main.hbs"),
  partialsDir: path.resolve(__dirname, '../views/partials')
}));
app.get('/about/company', (req, res) => {
  res.render('pages/about')
})

I have a directory structure like so:

views/partials/footer.hbs

views/layouts/main.hbs

views/pages/about/index.hbs
views/pages/about/about-only-partial-a.hbs
views/pages/about/about-only-partial-b.hbs

In my about.hbs file, I want to use the main.hbs layout but also reference some local partials (the ones name about-only-partial-a.hbs and about-only-partial-b.hbs

I've tried this code in my about.hbs:

{{> ./about-only-partial-a.hbs}}
{{> ./about-only-partial-b.hbs}}

But I constantly get this error

Error: [pages/about\index.hbs] The partial ./about-only-partial-a could not be found

Is there anyway I can use partials but override it to specify a path?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions