Meteor: Select template conditionally based on url argument from controller -


hi have route

#coffeescript     router.route 'tests/:slug/:type/question/add',       name: 'addquestion'       controller: testsaddquestioncontroller 

and have controller

@testsaddquestioncontroller = testsquestionscontroller.extend   template: 'mcqquestionform'   data: ->     questions: testquestions.find()       test: tests.findone slug: this.params.slug 

and want select template controller depending value of :type parammeter, tried 2 ways:

@testsaddquestioncontroller = testsquestionscontroller.extend   template: if this.params.type 'mcq' 'mcqquestionform' else 'somethingelse'   data: ->     questions: testquestions.find()       test: tests.findone slug: this.params.slug 

but approach error this.params undefined

second approach

 @testsaddquestioncontroller = testsquestionscontroller.extend       template: if router.current().route.params.type 'mcq' 'mcqquestionform' else 'somethingelse'       data: ->         questions: testquestions.find()           test: tests.findone slug: this.params.slug 

but applciation crashes approach, body know how access route parameters in order make conditionals select template controller?

here how our controller looks like:

@testsaddquestioncontroller = testsquestionscontroller.extend   template: ->     qtype = router.current().params.type     if qtype == 'practical'       'practicalquestionform'     else if qtype == 'mcq'       'mcqquestionform'   data: ->     questions: testquestions.find()       test: tests.findone slug: this.params.slug 

for reason (no idea why) if save current router param variable , use variable if statement works.

hope helps you.


Comments