bminer / node-blade

Blade - HTML Template Compiler, inspired by Jade & Haml
Other
320 stars 28 forks source link

Meteor: How to expose a variable as the view context for a template? #175

Closed halgorithm closed 11 years ago

halgorithm commented 11 years ago

According to https://github.com/bminer/node-blade/wiki/Using-Blade-with-Meteor,

<template name="foo">
 {{#each bars}}
   {{> bar}}
 {{/each}}
</template>

might look like this in Blade:

foreach bars as bar
  include "bar" exposing bar

However, the difference between these two is that Handlebar's way makes bar become this within the "bar" template. This allows the "bar" template to use {{name}} and {{whatever}} instead of {{bar.name}} and {{bar.whatever}}. How could you do that with blade?

Also, is there any way to expose a local under a different name, like include "bar" exposing { coolBar: bar } or include "bar" exposing bar as "coolBar"? Not sure what the syntax would be, or if that would even be the right way to accomplish such a thing...

bminer commented 11 years ago

However, the difference between these two is that Handlebar's way makes bar become this within the "bar" template. This allows the "bar" template to use {{name}} and {{whatever}} instead of {{bar.name}} and {{bar.whatever}}. How could you do that with blade?

Answer: you can't do that with Blade. It is a fundamental difference between Blade and Handlebars.

Also, is there any way to expose a local under a different name, like include "bar" exposing { coolBar: bar } or include "bar" exposing bar as "coolBar"? Not sure what the syntax would be, or if that would even be the right way to accomplish such a thing...

You also cannot really rename the locals. The only way would be something like this:

- var foo = bar
include "abc" exposing foo

... instead of just exposing bar, you expose foo, effectively renaming the local.

Closing this issue for now.