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

Deferred include (give names to includes or support variables in path) #282

Closed
dresende opened this issue Aug 1, 2011 · 17 comments
Closed

Comments

@dresende
Copy link

dresende commented Aug 1, 2011

I have an application with several templates, that have a base template. I then include each template (that corresponds to a view of the application). As Jade doesn't seem to support (I couldn't find), it would be great to have an include with a name like

include #content

or be able to use variables in the path like

include 'apps/#{app}/view'

Is this possible? Right now, I use a special string like "" and literally .replace() that with the sub template.

@tj
Copy link
Contributor

tj commented Aug 1, 2011

Jade doesn't currently have a runtime or anything, it just compiles straight to js so there's no logic involved in includes etc, which are included at compile time

@dresende
Copy link
Author

dresende commented Aug 2, 2011

What about...

- if
    ...
- else
    ...

This is at runtime... maybe one of the possibilities I gave could be simple to implement?

@tj
Copy link
Contributor

tj commented Aug 2, 2011

the problem is that the includes need to take place at compile time, they combine ASTs, otherwise it's basically just an Express partial()

@GuriK
Copy link

GuriK commented Sep 11, 2011

So we can't use variable in include ?

@tj
Copy link
Contributor

tj commented Sep 12, 2011

@GuriK nope, because it's compile-time

@ralphholzmann
Copy link

That sucks :(

@tj
Copy link
Contributor

tj commented Sep 13, 2011

we could eventually have something similar to partial() though we would have to cache a bunch of crap so it's not wasteful, and deal with the issues of options not cascading from the parent to the child properly such as the doctype etc, it's quite a bit more complicated, and at the end of the day it would basically be partial()

@ralphholzmann
Copy link

I understand the issue of complexity, its just tough to choose jade when you can't do something simple like

include header
p Lots of Content

Where header contains

html
  head
    title My Site!
  body

While this "works", it doesn't nest correctly. And likewise, you can't do something like this:

html
  body
    include #{myDynamicTemplateName}

This means I have to write a ton of boilerplate code for each template. Sad panda.

@tj
Copy link
Contributor

tj commented Sep 13, 2011

that would be pretty easy to do with a helper, basically just a few line cached readFileSync/jade.compile(). that being said the next release has template inheritance ready to go I just need to fix an error reporting bug

@ralphholzmann
Copy link

Cool! I'm looking forward to the template inheritance. Is there a branch or ETA?

@tj
Copy link
Contributor

tj commented Sep 13, 2011

it's in master actually, should be done pretty soon, the error reporting is pretty tough to get nice test coverage on so it's a bit of a PITA

@tj
Copy link
Contributor

tj commented Jun 17, 2012

This issue has been inactive for over 2 months so I'm closing it. If you think it's still an issue re-open. - tjbot

@tj tj closed this as completed Jun 17, 2012
@hmalaud
Copy link

hmalaud commented Apr 25, 2013

The issue seems old now, but has the functionality been added since then?

@ForbesLindesay
Copy link
Member

Template inheritance is usually a much better solution to this problem. Since includes must happen at compile time, it's not possible to implement this feature. Support for partials might be nice, but it adds far too much complexity and there's no real reason you can't add it yourself using fs.readFileSync/jade.compile

@diosney
Copy link

diosney commented Mar 31, 2014

Too bad :( This is a really neat feature to include since it maintain our section of code very clean.

So, several years later there is no plan to add this feature or a workaround not so complex like the above?

@acidjazz
Copy link
Contributor

lets get this in for the next version! #1990

@acidjazz
Copy link
Contributor

Dynamic includes would be so awesome, I've run into issues twice this week on projects where they would solve them immediately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants