0
votes

I have a functionality in my application to display customer listing and then edit page for all customers. I am getting error when user redirect to edit page "Expected template or null, found: undefined"

Below is my code for reference Route.js

Router.route('/user/:userId', function () {
  this.render('customeredit');
  this.layout('mainNav');
});

HTML

<template name="customeredit">
    {{#customerData}}
    {{fname}}
    {{/customerData}}
</template>

JS

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import '../templates/editUser.html';

import { Customers } from '../../imports/api/customers.js';

Template.customeredit.helpers({
    customerData: function() {
        var customerId = 'NpWkSWRpkQJKsNecG';
        console.log(customerId);
        console.log(Customers.findOne({_id: customerId}));
    }
});

Also please tell how we can fetch user id from url in my above JS file, as my generated URL is: http://localhost:3000/user/NpWkSWRpkQJKsNecG and i need to fetch "NpWkSWRpkQJKsNecG" in helper.

1

1 Answers

0
votes

Hopefully this addresses your issue and answers your question.

  1. Why are you receiving the "Expected template or null, found: undefined" error?

Have you supplied all the code for the page in your question? If so then I suspect the issue is in your template definition where you are using a custom block helper (e.g. {{#customerData}}).

Have you defined this block helper? I'm wondering if you are just trying to use the customerData Template helper instead. If that's the case then your Template definition should look like this:

<template name="customeredit">
    {{customerData}}
</template>

Template helper calls are just simply wrapped in {{ }}.

  1. How do you access the user id parameter from the url.

Using Iron Router, you can access the route parameter using this.params. You typically would look up the data first and then pass it along to the Template. For example:

Router.route('/user/:userId', function () {
  var user = Customers.findOne({_id: this.params.userId});
  this.render('customeredit', {data: user});
  this.layout('mainNav');
});