bminer / node-blade

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

Meteor integration, howto #30

Closed mlohr closed 12 years ago

mlohr commented 12 years ago

I have installed blade within my meteor environment, but don't know how to use it and or how to set it up.

As an "hello world" I have to next template file: views/hello.blade:

html
  head
  body
    p Hello world!

Now if I kick off meteor I get the next errors:

Errors prevented startup:

Exception while bundling application:
TypeError: Cannot call method 'toString' of undefined
    at /usr/lib/meteor/packages/blade/package.js:30:59
    at /usr/lib/meteor/lib/node_modules/blade/lib/blade.js:37:19
    at Compiler.compile (/usr/lib/meteor/lib/node_modules/blade/lib/compiler.js:90:10)
    at compile (/usr/lib/meteor/lib/node_modules/blade/lib/blade.js:36:12)
    at Object.compileFile (/usr/lib/meteor/lib/node_modules/blade/lib/blade.js:56:3)
    at /usr/lib/meteor/packages/blade/package.js:18:8
    at [object Object].add_file (/usr/lib/meteor/app/lib/bundler.js:196:5)
    at /usr/lib/meteor/app/lib/bundler.js:97:16
    at Array.forEach (native)
    at Function.<anonymous> (/usr/lib/meteor/app/lib/third/underscore.js:76:11)
 Your application is crashing. Waiting for file change.

Somehow tmpl is undefined??

mlohr commented 12 years ago

UPDATE

I removed the html tag from the template. This fixed the error on meteor bundeling.

But now I have an empty browser window, how to render? Will read the docs if I can fix this on my own...

mlohr commented 12 years ago

UPDATE

Ok now I know you need to have the main template called views/index.blade with something like:

body
  p Hello world!

Now this is shown!

bminer commented 12 years ago

Did you get it working? :) Sorry, I know there is very little documentation on this. I want to create a wiki page about Meteor integration. Any findings/watch-outs that we should post to the wiki?

bminer commented 12 years ago

Ah, just realized that you posted some content to the wiki. Thanks!

TrevorBurnham commented 12 years ago

The wiki page doesn't really explain how you render templates without writing the JavaScript code to do so yourself. That is, once you've created views/test.blade, how do you render the test template in body.blade? Is include 'body.blade' the right approach?

bminer commented 12 years ago

@TrevorBurnham - the only way to render templates is to write the JavaScript code to do so yourself. That being said, include statements certainly work fine in any template. What are you trying to do?

TrevorBurnham commented 12 years ago

@bminer I'm just trying to do basic templating. The wiki page currently says

Create templates in your views/ directory and render them as you would a Handlebars template.

But I would render a Handlebars template with the Handlebars syntax

{{> templateName}}

not by writing code somewhere to run Meteor.ui.render(Template.templateName) and inject the result into the DOM, which is the only way to render templates that's demonstrated on that wiki page.

An example project (like, say, a Blade version of the Leaderboard app) would be extremely helpful.

bminer commented 12 years ago

Right... the Handlebars syntax for includes is {{> templateName}}. In Blade, the equivalent is include "templateName.blade". Don't put Meteor.ui.render calls in your templates. Does that help? You are welcome to add/modify the wiki page as you see fit. :)