{{variable}} // variable or object property
// Array of Objects
{{#each doc}} //"docname" is a property of each object in "doc" Array
{{docname}}
{{/#each}}
// if else statement
{{#if userLoggedIn}}
{{> indexhtml}}
{{else}}
{{> loginMenu}}
{{/if}}
//--------------------
< body>
{{> menu}} // template name
< /body
{{#each menuitems}}
{{title}}
{{/each}}
Temlplate.menu.menuitems = function(){
return [
{link:'#1',title:'firstlink'},
{link:'#2',title:'secondlink'}
];
}
Temlplate.menu.currentName = function(){
return Session.get('curname');
}
Temlplate.menu.events = {
'click .node-class' : function() {
// do something
Session.set('curname','Maxim');
}
}
// insert data to DB
documents = new Meteor.Collection('documents');
documents.insert({ name:'default', content: 'empty' });
// update entry in DB
documents.update({'_id':currentID}, {$set: {name: 'myDocument'}});
documents.update({'_id':currentID}, {$set: {content: '<h1>Hello!</h1>'}});
//find collection
documents.find({'name':'Maxim'});
Download and install Meteor(link at forst slide)
Open command panel, go to project folder, Use "meteor create"
Creating base folders, files , app structure
homepage.html in homepage module
menu.html in menu module
<template name="homepage">
// write homepage markup
</template>
<template name="menu">
// write menu module html markup
</template>
<template name="homepage">
// here homepage index markup
// .....
// now we add MENU template to index template
{{> menu}}
</template>
< body>
{{> homepage}}
< /body>
Yes, we add our template in BODY tag. We don`t need to add any html base tags like DOCUMENT, head, footer, etc.
create homepage.js in "homepage" folder
create menu.js in "menu" folder
create server.js in "Server" folder
Look at the picture and let`s Go to the "server"
Meteor.startup()
Meteor.methods()
Meteor.Collection
collection.insert
collection.update
collection.find
collection.findOne
Meteor.Session
Open server.js file
Meteor.startup(function (){
documents = new Meteor.Collection('documents');
var fs = Npm.require('fs');
//init Meteor methods here
Meteor.methods({
delAllData:function () {
//here we remove all data from documents collection
documents.remove({});
},
insertNewDoc:function(docName, clientId, websiteID){
// here we add new enrty to DB
documents.insert({
'docName':docName,
'clientId': clientId,
'websiteId': websiteID,
'docText':'document is empty'
});
}
})
});
Open menu.js file
menuItems = new Meteor.Collection('menuItems')
Template.menu.items = function() {
return menuItems.find({});
}
Template.menu.events = {
'click a' : function(e) {
// do something on click
},
'mouseenter a' : function(e) {
//do something
}
}
Open menu.html file
<template name="menu">
{{#each items}}
<a href="{{link}}" target="_blank">{{title}}
{{/each}}
</template>
Now each link have Binded "click and mouseenter" events. And we will se on page all links from DB Collection
**Meteor Account Managment**
- faceBook package
- loginPassword basic package
- gitHub Package
**Deploy/Delete Application**
- meteor deploy myapp.meteor.com (remember http://vocabulary.meteor.com/)
- With settings -> meteor deploy myapp.meteor.com --settings ---
****delete app****
- meteor deploy myapp.meteor.com --delete
**test examples:**
- http://cmstest.meteor.com/ - user:admin, pass:maxim
Prepared by Maxim Shturmin