# How to render template when adding custom route in discourse

**URL:** <https://meta.discourse.org/t/how-to-render-template-when-adding-custom-route-in-discourse/64374>\
**Category:** Development\
**Created:** [June 12, 2017, 6:24pm UTC](https://meta.discourse.org/t/how-to-render-template-when-adding-custom-route-in-discourse/64374 "2017-06-12T18:24:22Z")\
**Posts on this page:** 2\
**Page:** 1

## AI-generated summary

[net_deamon](/t/-/64374/1) is attempting to add a custom non-admin route (`/customroute`) in Discourse but encounters issues with template rendering. Initially, the route outputs raw JSON text instead of rendering the Handlebars template, despite using `render json: {title:"custom route"}` in `plugin.rb` and defining the route in `customroute-map.js.es6` and `route/customroute.js.es6`. The user tried implementing `renderTemplate` to fix this but received an error: "Assertion Failed: Cannot call `Ember.get` with an empty string".

In a subsequent post, [net_deamon](/t/-/64374/2) provides a solution, stating that the template must be added using `Discourse.replaceState('customroute')`. The corrected `route/customroute.js.es6` implementation involves setting up the controller with data fetched via AJAX and then calling `DiscourseURL.replaceState` to ensure the template renders correctly.

<div class="post-metadata">

**Author:** ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)\
**Post date:** [June 12, 2017, 6:24pm UTC](https://meta.discourse.org/t/how-to-render-template-when-adding-custom-route-in-discourse/64374/1 "2017-06-12T18:24:22Z")

</div>

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

Required route `http://discourse.org/customroute`

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

 ![](https://global.discourse-cdn.com/meta/original/3X/a/f/afe774ebaf5c9733c232b349136c1aff6215af73.png)

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() {
      this.render('/customroute');
 }

```

But then I get the error `"Assertion Failed: Cannot call `Ember.get` with an empty string"`

---

<div class="post-metadata">

**Author:** ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)\
**Post date:** [July 2, 2017, 3:52am UTC](https://meta.discourse.org/t/how-to-render-template-when-adding-custom-route-in-discourse/64374/2 "2017-07-02T03:52:04Z")

</div>

You have to add the template by using

```
Discourse.replaceState(`customroute`)

```

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 })
      DiscourseURL.replaceState(`/customroute`)
    })
  }
})

```
