I've installed markdown package on Meteor:
meteor add markdown
And test it successfully:
<body>
{{#markdown}}
#Hello world!#
{{/markdown}}
</body>
Ok!
Now I would like to import a markdown from a file and I had try in this way:
if (Meteor.isClient) {
Session.set("markdown_data","MDFile.md");
Template.myTemplate.helpers({
markdown_data: function() {
return Session.get("markdown_data");
}
});
}
And in html:
<body>
{{#markdown}}{{{markdown_data}}}{{/markdown}}
</body>
But nothing appears, neither on webpage or in web-console or terminal.
Where I'm wrong?
if (Meteor.isClient) {
Markdown = new Mongo.Collection("markdown");
Template.myTemplate.helpers({
markdown_data: function() {
var markdown = Markdown.findOne();
return markdown && markdown.data;
}
});
}
if (Meteor.isServer) {
Markdown = new Mongo.Collection("markdown");
Meteor.startup(function () {
if(Markdown.find().count()===0){
Markdown.insert({
data: Assets.getText("teamProgramming.md")
});
}
});
}
It's not going to work this way, you should put your markdown file under the private directory, load it as an asset server-side and send it to the client using a collection :
private/MDFile.md
#Hello world!#
lib/collections/markdown.js
Markdown=new Mongo.Collection("markdown");
server/startup.js
Meteor.startup(function(){
if(Markdown.find().count()===0){
Markdown.insert({
data: Assets.getText("MDFile.md");
});
}
});
server/collections/markdown.js
Meteor.publish(function(){
return Markdown.find();
});
client/views/main.html
<body>
{{#markdown}}
{{markdownData}}
{{/markdown}}
</body>
client/views/main.js
Template.body.helpers({
markdownData:function(){
var markdown=Markdown.findOne();
return markdown && markdown.data;
}
});