tvshajeer
tvshajeer

Reputation: 1329

How to use a template with textboxes loaded with data passed from a calling template in ember.js

I'm trying to make a addstudent template which can be rendered with data if clicked on editstudent option from another template.

I don't want to make different templates for addStudentDetails and EditstudentDetails. how to create a single template for this both functions.

can anyone help me with this?

Upvotes: 3

Views: 50

Answers (1)

imahungry
imahungry

Reputation: 126

I see a couple ways of doing this.

  1. Handlebar template, using conditionals. Then in your controller you can control whether you want to edit or add. The ember guide has a good example of this for controlling state.

  2. Or you can use Routes and Resources. Possibly a Parent Resource called Student and then routes called edit and add. But you said you didn't want to use different templates so I'm assuming you'll probably want to use #1.

//inside your controller
App.StudentController = Ember.ObjectController.extend({
  editStudent: true // or false
});
<!-- handlebars template possibly called studentTemplate -->
{{#if editStudent}}
  <!-- code for editStudent -->
{{else}}
  <!-- code for addStudent -->
{{/if}}

Hope that answers your question.

Upvotes: 1

Related Questions