How to render template when adding custom route in discourse

(Net Deamon) #1

I am trying to add a custom route (non-admin route) discourse.

Required route

I am able to add the route, but the problem is that instead of rendering the template, it just outputs the json text.

My json data in plugin.rb is

render json: {title:"custom route"}

My customroute-map.js.es6 contains

export default function() {
  this.resource('customroute', { path: '/customroute' })

In the route/customroute.js.es6

export default Discourse.Route.extend({
   model:function() {
     return ajax('/customroute.json');

By doing so, I only get the json data in the template. But the customroute.hbs - handlebar template is not rendered.

I tried using the renderTemplate,

 renderTemplate: function() {

But then I get the error "Assertion Failed: Cannot callEmber.getwith an empty string"

(Net Deamon) #2

You have to add the template by using


So the route/customroute.js.es6 will be

export default Discourse.Route.extend({

  model: function(params) { return params },

  setupController: function(controller, params) {
    ajax(`/customroute.json`).then(function(data) {
      controller.setProperties({ model:data })