Search code examples
meteorpugiron-router

Passing data from router to Jade template


I have Jade template:

template(name="mainLayout")
  h1= data
  h3 Meteor.js Example

When I try to pass data to template in router:

Router.route "/", () ->
  @render "index", data: "My Awesome Page"

This is not working. How to pass the data into template?


Solution

  • data passed in the router is this in the jade.

    So instead of:

    h1= data
    

    Try:

    h1= this
    

    If you want to pass more data, you can do like this:

    template(name="mainLayout")
      h1= this.data1
      h2= this.data2
      // or shorted, just ignore the this.
      h1= data1
      h2= data2
      h3 Meteor.js Example
    
    Router.route "/", () ->
      @render "index", data: { data1: "My Awesome Page", data2: "Foobar" }