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

Can't render partials in sub-directories on level 3 above #122

Closed
hoanghuu opened this issue Mar 8, 2016 · 5 comments
Closed

Can't render partials in sub-directories on level 3 above #122

hoanghuu opened this issue Mar 8, 2016 · 5 comments
Assignees
Labels

Comments

@hoanghuu
Copy link

hoanghuu commented Mar 8, 2016

Here is directories constructor:
-views
--------partials
-------------app
-------------------home
------------------------list.hbs
-------------smartphone
------------------home
------------------------list.hbs
------------------------focus.hbs
---------index.hbs

in index.hbs:

{{#if focusNews }}
{{> smartphone/home/focus data=focusNews }}
{{/if}}

When render page, my app throw exception not found partial home/focus.

I think you need change the function registerPartials on module.

@chimericdream
Copy link

I ran into this same issue myself. It turned out to be a really simple fix. I submitted a PR with the fix in place.

@eshengsky
Copy link
Contributor

I ran into this issue too, any new progress?

@hoanghuu
Copy link
Author

hoanghuu commented May 18, 2017

You can modify function registerPartials in file node_modules\hbs\lib\hbs.js as code below:

Instance.prototype.registerPartials = function (directory, done) {
  var handlebars = this.handlebars;

  var register = function(filepath, done) {
    var isValidTemplate = /\.(html|hbs)$/.test(filepath);

    if (!isValidTemplate) {
      return done(null);
    }

    fs.readFile(filepath, 'utf8', function(err, data) {
      if (!err) {
        var ext = path.extname(filepath);
        var templateName = path.relative(directory, filepath)
          .slice(0, -(ext.length)).replace(/[ -]/g, '_').replace(/\\/g, '/');
        handlebars.registerPartial(templateName, data);
      }

      done(err);
    });
  };

  walk(directory).on('file', function(root, stat, next) {
    register(path.join(root, stat.name), next);
  }).on('end', done || function() {});

};

it work fine for me.

@eshengsky
Copy link
Contributor

eshengsky commented May 19, 2017

@hoanghuu I modified the source, and it woks fine now. But it's not a good idea to modify the module directly. Could author fix the bug?

@dougwilson
Copy link
Contributor

Hi everyone, I am working to help on this module now and going though the issues and pull requests. I see there are two pull requests to fix this issue. Neither had any tests, and even then, there was no CI on Windows. I have now setup CI on Windows and just added a test to PR #143 which I will be merging to (finally) get this fixed for you all ❤️

@dougwilson dougwilson added the bug label Feb 22, 2019
@dougwilson dougwilson self-assigned this Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants