bminer / node-blade

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

Interpolation for parametrized blocks' arguments #100

Closed alvaro-cuesta closed 12 years ago

alvaro-cuesta commented 12 years ago

layout.blade

block title(text)
  h1 text

view.blade

include "layout.blade"
- var text = "example"
render title("#{text}")

Rendering view.blade yields<h1>#{text}</h1>while I would expect<h1>example</h1>.

Am I doing something wrong or is this just not possible in current Blade?

bminer commented 12 years ago

Try render title (text) instead. ;)

alvaro-cuesta commented 12 years ago

That was a simplified example, my interpolated string is much more complex and I can't interpolate into a variable using JS, so... I guess I'm out of luck?

bminer commented 12 years ago

@alvaro-cuesta - You can't use interpolation in parameterized blocks' arguments. BUT... You're probably not out of luck. Could you post your example?

alvaro-cuesta commented 12 years ago

@bminer, it's more or less the same but the interpolated string is not a simple variable. I'm trying to use this in several places:

- var date = new Date
render title("R&aacute;ndome - #{pageTitle} - #{date.getHours()}:#{date.getMinutes()}")
render random("Your random number is #{parseInt(Math.random() * (max-min) + min)}.")

etc.

Of course I could assemble the strings using plain JS, but interpolation is SOOOO cool I can't live without it :P I guess CoffeeScript (#39 :heart:) would do the trick.

bminer commented 12 years ago

Right, yes. Just assemble the strings using plain JS. String concatenation is cool, too. ;) Remember how hard it was to concatenate strings in C? All this fancy interpolation stuff, geez!

Just...

- var date = new Date
render title("R&aacute;ndome - " + pageTitle + " - " + date.getHours() + ":" + date.getMinutes())

and similarly...

render random("Your random number is " + parseInt(Math.random() * (max-min) + min) + ".")
bminer commented 12 years ago

So, allow me to revise my prior post...

If you want string interpolation here, you are out of luck. As you pointed out, string interpolation doesn't work in JavaScript.