Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template helpers fail on relative paths #1597

Closed
irothschild opened this issue Apr 25, 2014 · 5 comments
Closed

Template helpers fail on relative paths #1597

irothschild opened this issue Apr 25, 2014 · 5 comments
Assignees
Labels
Milestone

Comments

@irothschild
Copy link

@irothschild irothschild commented Apr 25, 2014

I have server options that include something like:

            views: {
                engines: {
                    html: 'handlebars'
                },
                basePath: 'foobar',
                path: 'templates',
                defaultExtension: 'html',
                helpersPath: 'helpers',
           }

This works fine for loading the templates but the helpers don't load properly.

My template helpers are in foobar/helpers. In file hapi/lib/views.js Manager.prototype._loadHelpers finds all the helper files properly with paths like foobar/helpers/myhelper.js but then it does a require() on that path which fails to load the file.

Is basePath intended to be a full path?

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Apr 26, 2014

It should be a relative or absolute which means starting with '/' or './'. Let me know if that helps.

@irothschild
Copy link
Author

@irothschild irothschild commented Apr 26, 2014

Relative paths don't seem to work because Path.join() strips the leading dot. The only way I could get it to work without code changes is to use an absolute path for basePath.

hueniverse pushed a commit that referenced this issue Apr 26, 2014
@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Apr 26, 2014

I think your problem is the base path. It needs to be relative to the current working directory. See the two tests I've added showing relative paths working.

@hueniverse hueniverse closed this Apr 26, 2014
@irothschild
Copy link
Author

@irothschild irothschild commented Apr 26, 2014

Well this confused me. But in fact the tests are only passing because the helpers have already been successfully required with the absolute path in previous tests. If you move the new relative path tests so they're the first helper tests, they will fail.

  1. Views #render loads helpers using relative paths:
  AssertionError: expected undefined to equal '<p>This is all UPPERCASE and this is how we like it!</p>'

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Apr 26, 2014

Interesting...

@hueniverse hueniverse reopened this Apr 26, 2014
@hueniverse hueniverse added bug and removed question labels Apr 27, 2014
@hueniverse hueniverse changed the title Template helpers path issue Template helpers fail on relative paths Apr 27, 2014
@hueniverse hueniverse added this to the 4.0.3 milestone Apr 27, 2014
@hueniverse hueniverse self-assigned this Apr 27, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants