Search code examples
spine.jseco

Rendering views in spineJS?


Just so you know this is my first question here on stackoverflow, so I apologize if something is wrong with my question.

OK, So I have just started using spine, it is my first delve into MVC frameworks and I am having trouble with rendering a .eco template.

It is probably something really basic but whenever i run 'hem server', all I see is a blank page?

Here is the hello.coffee controller:

Spine = require('spine')

class Hello extends Spine.Controller
    constructor: ->
        super

    render: ->
        @html require('views/view')

module.exports = Hello

Here is views/view.eco

<h1>Hello World</h1>

And here is app/index.coffee

require('lib/setup')

Spine = require('spine')
Hello = require('controllers/hello')

class App extends Spine.Controller
    constructor: ->
        super
        @hello = new Hello
        @append @hello

module.exports = App

When I visit the app with the JS console open no errors are produced and if I vist localhost:9294/test everything is ok?

Thanks in advance to anyone can help me and my noobiness! ;)


Solution

  • you can also have your controller constructor method call the render for you:

    class Hello extends Spine.Controller
      constructor: ->
        super
        @render()
    
      render: ->
        @html require('views/view')