-1

Page rendering is not working with iron:router please help me.Rendering is not working with code.Please find the bellow attached code.And we are users meteor add iron:router 0.9.4.And we used meteor 0.9.3.1. Page rendering is not working

<head>
</head>
<body >
    <div>
        {{> players}}
    </div>
</body>

<template name ="editform">
  <div class="container">
    <div class="row" style="border-bottom: 5px solid gray;">
        <h2>Profile</h2>
    </div>
    <div id="wrapper">
        <table>
            <tr>
               <td>First name:</td>
               <td><input type="text" name="pff_name"/></td>
            </tr>
            <tr>
               <td>Last name:</td>
               <td><input type="text" name="pfl_name"/></td>
            </tr>
            <tr>
               <td>Email Address:</td>
               <td><input type="email" name="pfemail"/></td>
            </tr>
            <tr>
               <td>Phone number:</td>
               <td><input type="text" name="pfname"/></td>
            </tr>
            <tr>
               <td>Company or Organization:</td>
               <td><input type="url" name="pfname"/></td>
            </tr>
        </table>        
    </div>
  </div>
</template>

<template name="players">
     <div>
         <table class="table table-condensed table-striped table-bordered table-hover no-margin">
             <tr>
                <th>IP</th>             
                <th></th>
            </tr>
            {{#each scorers}}
            <tr>
                <td><a href="{{ pathFor  'editform' }}" >{{ ip }}</a></td>              
                <td></td>
            </tr>
           {{/each}}
       </table>
    </div>
</template>

This router.js

Router.route("/", function() {
    this.render("route");
});
durrrr
  • 352
  • 2
  • 15

2 Answers2

1

It is unclear what you are trying to achieve.
May I suggest you to start by reading the Meteor Docs for starters.

For a simple app like this one you can use a structure like this:
/client (client side code files)
/server (server side code files)
collections.js
Check out a good way of structuring your app here.

First, you don't need the <head> and <body> tags here.
Then, you can create a layout template in client folder in which you can set the players template to render, also to add header, footer, etc to your page.

layout.html

<template name="layout">
    {{>players}}
</template>


Then you need a players template in client folder as well. I'm gonna go ahead and produce an simple example here to get you going. The user input value is collected, inserted into Players collection and for each player in that collection a new table row is created in div.result using a {{players}} helper.

players.html

<template name="players">
    <div class="container">
        <div class="row" style="border-bottom: 5px solid gray;">
            <h2>Profile</h2>
        </div>
        <div id="wrapper">
            <table>
                <tr>
                    <td>First name:</td>
                    <td><input type="text" id="pff_name" /></td>
                </tr>
                <tr>
                    <td>Last name:</td>
                    <td><input type="text" id="pfl_name" /></td>
                </tr>
            </table>
            <button class="insert">Submit</button>
        </div><br/>
        <div id="result">
          <table class="table table-condensed table-striped table-bordered table-hover no-margin">
            <tr>
              <th>First Name</th>
              <th>Last Name</th>
            </tr>
            {{#each players}}
            <tr>
                <td>{{firstname}}</td>
                <td>{{lastname}}</td>
            </tr>
            {{/each}}
          </table>
        </div>
    </div>
</template>



collections.js
Create a new Meteor Collection called Players, which will store all the added documents.

Players = new Meteor.Collection("players");


players.js
Here, the players helper will return a cursor and a created Meteor method named addPlayer is called.

Template.players.helpers({
    players: function() {
        return Players.find();
    }
});

Template.players.events({
    'click .insert': function(event, template) {
        var first = $('#pff_name').val();
        var last = $('#pfl_name').val();
        if(first !== "" && last !== "") {
            Meteor.call("addPlayer", first, last);
        }
        $('#pff_name').val("");
        $('#pfl_name').val("");
    }
});


server.js
Adding the player to Players collection

Meteor.startup(function () {
    Meteor.methods({
        addPlayer: function(fname, lname) {
            Players.insert({firstname: fname, lastname: lname});
        }
    })
});


routrer.js
Tell Iron Router to render the players template

Router.map(function () {
    this.route('players', {
        path: '/',
        template: 'players',
        layoutTemplate: 'layout'
    })
});



EDIT: You are using IronRouter version 0.9.4, but your route is defined for the new version.
Either update IronRouter to iron:router@1.0.0-pre3 or follow the notation I gave for this version.

Community
  • 1
  • 1
durrrr
  • 352
  • 2
  • 15
0

Sorry to be blunt, but you really need to read this.

At the very, very top it says:

Router.route('/', function () {
  this.render('Home');
});

When the user navigates to the url "/", the route above will render the template named "Home" onto the page.

You have the line this.render("route"); in your router, but no template named "route".

richsilv
  • 7,993
  • 1
  • 23
  • 29