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

Better Pathing #1467

Closed
nijikokun opened this Issue Mar 19, 2014 · 14 comments

Comments

Projects
None yet
5 participants
@nijikokun

nijikokun commented Mar 19, 2014

Is there a way to do absolute pathing instead of relative pathing?

This complicates a lot of things when you are doing a large project and you are attempting to extend one file, if you nest folders at all you will understand this pain:

extends ../../../../../Framework/Layout/complete

If there is a better way of doing this then there needs to be better documentation than the one that exists.

@matejkramny

This comment has been minimized.

matejkramny commented Mar 19, 2014

+1 would be nice to have key words like you have in require.js..

Matej Kramny

On 19 Mar 2014, at 08:32 pm, Nijiko Yonskai notifications@github.com
wrote:

Is there a way to do absolute pathing instead of relative pathing?

This complicates a lot of things when you are doing a large project and you
are attempting to extend one file, if you nest folders at all you will
understand this pain:

extends ../../../../../Framework/Layout/complete

Reply to this email directly or view it on
GitHubhttps://github.com//issues/1467
.

@matejkramny

This comment has been minimized.

matejkramny commented Mar 19, 2014

Eg:
extends responsive

This uses a predefined file name 'responsive' which maps to
/views/layouts/responsive.jade and can be used from any view from any
directory.
I understand this brings up logistical issues but would be very useful..

Matej Kramny

On 19 Mar 2014, at 08:35 pm, Matej Kramny matej@matej.me wrote:

+1 would be nice to have key words like you have in require.js..

Matej Kramny

On 19 Mar 2014, at 08:32 pm, Nijiko Yonskai notifications@github.com
wrote:

Is there a way to do absolute pathing instead of relative pathing?

This complicates a lot of things when you are doing a large project and you
are attempting to extend one file, if you nest folders at all you will
understand this pain:

extends ../../../../../Framework/Layout/complete

Reply to this email directly or view it on
GitHubhttps://github.com//issues/1467
.

@nijikokun

This comment has been minimized.

nijikokun commented Mar 19, 2014

Parser runs the inclusions and extensions before it runs the variable parsing. (Makes sense for some things, but it complicates others)

I was thinking that if the path starts with / then it's absolute positioning from the root folder either views/ or whatever is your root view folder, or the the project itself.

@ForbesLindesay

This comment has been minimized.

Member

ForbesLindesay commented Mar 19, 2014

Yep, just include the basedir option and start your path with a /

@nijikokun

This comment has been minimized.

nijikokun commented Mar 19, 2014

Include the option where? I'm using middleware for about 80% of views.

@ForbesLindesay

This comment has been minimized.

Member

ForbesLindesay commented Mar 20, 2014

e.g.

in express:

res.render('view.jade', {basedir: __dirname + '/views');

or at the top level:

app.locals.basedir = __dirname + '/views';

In anything else, somehow jade will be being called as something like:

var html = jade.renderFile('view.jade', locals);

Just add basedir as a local.

locals.basedir = __dirname + '/views';
var html = jade.renderFile('view.jade', locals);

If you're doing compile/render as separate steps then you need to pass it to jade.compile e.g.

var fn = jade.compile('view.jade', {basedir: __dirname + '/views'});
var html = fn(locals);
@matejkramny

This comment has been minimized.

matejkramny commented Mar 20, 2014

@forbes nice, would this work from inside a jade template?
Does it apply to include and extends?

Thanks

Matej Kramny

On Thursday, 20 March 2014 at 10:05, Forbes Lindesay wrote:

e.g.
in express:
res.render('view.jade', {basedir: __dirname + '/views');

or at the top level:
app.locals.basedir = __dirname + '/views';

In anything else, somehow jade will be being called as something like:
var html = jade.renderFile('view.jade', locals);

Just add basedir as a local.
locals.basedir = __dirname + '/views'; var html = jade.renderFile('view.jade', locals);

If you're doing compile/render as separate steps then you need to pass it to jade.compile e.g.
var fn = jade.compile('view.jade', {basedir: __dirname + '/views'}); var html = fn(locals);


Reply to this email directly or view it on GitHub (#1467 (comment)).

@ForbesLindesay

This comment has been minimized.

Member

ForbesLindesay commented Mar 20, 2014

It does apply to include and extends. Not sure what you mean by "would this work from inside a jade template". You can't set the basedir from inside the template as it must be set before the template can be compiled.

@matejkramny

This comment has been minimized.

matejkramny commented Mar 20, 2014

Sorry i just meant that if you set this basedir in express, then if it is
possible to include things from jade..

On 20 Mar 2014, at 11:05 am, Forbes Lindesay notifications@github.com
wrote:

It does apply to include and extends. Not sure what you mean by "would this
work from inside a jade template". You can't set the basedir from inside
the template as it must be set before the template can be compiled.

Reply to this email directly or view it on
GitHubhttps://github.com//issues/1467#issuecomment-38155009
.

@ForbesLindesay

This comment has been minimized.

Member

ForbesLindesay commented Mar 20, 2014

Yes, you set basedir in express/your framework of choice. You then include things from jade.

@saviomd

This comment has been minimized.

saviomd commented Nov 6, 2015

Why isn't this documented? This is f****** awesome!

@TimothyGu

This comment has been minimized.

Member

TimothyGu commented Nov 6, 2015

@saviomd it was just documented 6 days ago :)

@saviomd

This comment has been minimized.

saviomd commented Nov 7, 2015

@TimothyGu

This comment has been minimized.

Member

TimothyGu commented Nov 7, 2015

Yes, we usually update the docs every time we make a new release.

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