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

sharing variables across blocks in jade #1603

Open
DTrejo opened this issue Jul 24, 2014 · 5 comments
Open

sharing variables across blocks in jade #1603

DTrejo opened this issue Jul 24, 2014 · 5 comments

Comments

@DTrejo
Copy link

DTrejo commented Jul 24, 2014

@dschnare's great article on how to share variables in #jadelang

http://darrenschnare.com/blog/2013/08/14/sharing-variables-with-jade-templates

Could be a good addition to the docs!

Thanks Forbes for maintaining Jade!
D

@ForbesLindesay ForbesLindesay changed the title [docs] sharing variables across blocks in jade sharing variables across blocks in jade Sep 24, 2014
@dschnare
Copy link

Hey thanks @DTrejo, I wrote that article so far back I had forgotten about it. That technique really does come in handy for sure. You are right though, generally speaking it's a technique to share variables across blocks not just templates. I remember when I wrote the article I had only spent a few days with Jade so I hadn't realized its general utility.

@jordancalder
Copy link

I have been running into issues with this the last few days. Am I to understand that variables passed to a certain view, will not be available to the base layout that it extends?

If this is the case, I am seeing a problem. In my base layout file, I'd like the navbar to display user information. But it would be tedious to add a block to every single view in order to expose those variables to the layout. Is there a way to expose those user vars once globally so that the layout can use them across all views?

@DTrejo
Copy link
Author

DTrejo commented Nov 11, 2014

@jordancalder yes there is! Follow this example here, and put ALL your variables in the block that goes at the very top of the layout. This will expose those variables to anything that comes after them in the layout.

See this great example: http://darrenschnare.com/blog/2013/08/14/sharing-variables-with-jade-templates/

good luck!
D

@jordancalder
Copy link

@DTrejo Thanks for the response. Maybe I'm not fully understanding, but doesn't this mean that in every view that extends the layout, I will have to add a block that passes those variables to the layout?

@DTrejo
Copy link
Author

DTrejo commented Nov 11, 2014

hey, yes.

It's not too much of a change, and you only need to do it when it is trying
to expose variables to the WHOLE layout. e.g. if you are changing meta tags
from inside a jade file that extends the layout.

Cheers,
D

On Tue, Nov 11, 2014 at 9:17 AM, Jordan Calder notifications@github.com
wrote:

@DTrejo https://github.com/DTrejo Thanks for the response. Maybe I'm
not fully understanding, but doesn't this mean that in every view that
extends the layout, I will have to add a block that passes those variables
to the layout?


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

See my projects at dtrejo.com
Read my tips for developers dtrejo.com/blog

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

No branches or pull requests

4 participants