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
Comments
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. |
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? |
@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! |
@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? |
hey, yes. It's not too much of a change, and you only need to do it when it is trying Cheers, On Tue, Nov 11, 2014 at 9:17 AM, Jordan Calder notifications@github.com
See my projects at dtrejo.com |
@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
The text was updated successfully, but these errors were encountered: