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

Already on GitHub? Sign in to your account

dust: support relative partial paths #67

wants to merge 3 commits into


None yet
5 participants

jmoyers commented Oct 7, 2012

  • Shared relative path partial test added
  • Absolute path > relative path > options.view > default to './views'
  • Should very rarely cost an extra failed readFile
  • Its likely to work on the first pass, its usually a flat views/ folder

jmoyers added some commits Oct 7, 2012

@jmoyers jmoyers dust: default relative path, fall back on views/ 7d64558
@jmoyers jmoyers Shared test for relative path partials
* Look for options.filename so we don't waste a call to fs
* Behavior is absolute path > relative path > default views
@jmoyers jmoyers Actually support absolute path 88537af

@tj tj commented on the diff Oct 10, 2012

+ }
+ var path = partial,
+ absolutePath = '/' === path[0];
+ // If we have a parent filename, try relative path
+ if (options.filename && !absolutePath) {
+ path = dirname(options.filename) + '/' + path;
+ } else if (!absolutePath) {
+ path = views + '/' + partial;
+ }
+ read(path, options, function (err, str) {
+ if (err) {
+ // Fall back on views/partial
+ return read(views + '/' + partial, options, callback);

tj Oct 10, 2012


IMO we shouldn't have this part, if it's relative and filename is present then we use that, absolute, or otherwise your conditional above will default it to this anyway


jmoyers Oct 10, 2012

Yeah, thats fine. The case it doesn't handle (options.filename exists and is in a subdirectory, but the template referenced in the partial is in the defaults views directory) probably won't happen often or is more properly handled through a ../ relative path. I can see this happening for a header and footer referenced in many templates.


tj Oct 17, 2012


but if it's not absolute, and no filename is given you're already defaulting to views/partial, unless im missing something

durango commented Jul 9, 2013

What's going on with this PR?

Is this PR still alive? I'm a great fan of relative paths for partials ;)


doowb commented Sep 17, 2017

Closing since partial paths are handled differently now.

@doowb doowb closed this Sep 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment