Using Meteor Iron-Router how can I either render data as JSON or simply display it \"raw\" (without a layout template)
Essentially I want to be able to do s
See: https://github.com/EventedMind/iron-router/issues/114
(Note the comment amending the content type.)
Make a raw layout template
<template name="direct_layout">
{{> yield}}
</template>
Then use that as your layoutTemplate to directly use your template.
this.route('rawdata', {
path: '/raw/:collection',
layoutTemplate: 'direct_layout',
template: 'raw'
});
I'm not sure whether you're using this as a placeholder for your actual code. If you intend to render data using JSON or actual raw text. You might want to consider using server-side routes. You should do something like this instead:
Note that this is server side code, unlike the above which runs on the client side:
this.route('serverRoute', {
where: 'server',
path: '/your-route',
action: function() {
var data = {this_is:'a json object'}
this.response.writeHead(200, {'Content-Type': 'application/json'});
this.response.end(JSON.stringify(data));
}
});
Have a look at Server side rendering on Iron-Router: https://github.com/EventedMind/iron-router/blob/master/DOCS.md#server-side-routing