Skip to content

Instantly share code, notes, and snippets.

@awei01
Last active October 6, 2015 18:33
Show Gist options
  • Save awei01/618a20cf6967440bda67 to your computer and use it in GitHub Desktop.
Save awei01/618a20cf6967440bda67 to your computer and use it in GitHub Desktop.
<head>
	<title>9tailors Admin</title>
</head>
<body>
	{{| > header }}

	{{ foo.bar }}

	{{ foo.baz }}

	<div id="modal" class="">

		{{ >Template.dynamic template=getModal data=getFoo }}

	</div>

	<a id="testclick">test click</a>
</body>

<template name="foo_clients_form">

	<p>
		{{ getData }}<br/>
		{{ getData.bar }}<br/>
		{{ otherHelper "see" }}<br/>
		why isn't this rendering?
		stuff from inside the template
	</p>
</template>



<head>
	<title>9tailors Admin</title>
</head>
<body>
	{{ > header }}

	{{ #with makeDataForModal }}
		{{ #if modalName }}
			{{ #modal this }}
			{{ /modal }}
		{{ /if }}
	{{ /with }}
</body>

<template name="modal">
	<div id="modal" class="">
		I'm the modal
		{{ >Template.dynamic template=modalName data=makeDataForContext }}
	</div>
</template>

<template name="foo_clients_form">

	<p>
		why isn't this rendering?
		stuff from inside the template
	</p>
</template>
'use strict';

var TmplBody = Template.body;
var __modal = new ReactiveVar('');

TmplBody.onCreated(function() {
	var instance = this;
	instance.autorun(function() {
		FlowRouter.watchPathChange();
		var modal = FlowRouter.getQueryParam('modal');
		console.log('tracker changed');
		__modal.set(modal);
	});
});

//var __tester = new ReactiveVar(0);

TmplBody.helpers({
	foo: {
		bar: "foo bar",
		baz: function() {
			console.log('rerunning foo.baz');
			return 'this is baz'
		}
	},
	getFoo: function() {
		console.log('getting foo');
		return { bar: "bar" };
	},
	getModal: function() {
		console.log('getting modal');
		var modal = __modal.get();
		if (modal) {
			return 'foo_' + modal;
		}
	},
});

Template.body.events({
	"click #testclick": function(event, instance) {
		console.log(this, event, instance);
	}
});

Template.foo_clients_form.helpers({
	getData: function() {
		return Template.currentData();
	},
	otherHelper: function(string) {
		return 'other helper: ' + string;
	}
});




'use strict';

var TmplBody = Template.body;
//var __modal = new ReactiveVar('');

TmplBody.onCreated(function() {
	var instance = this;
	instance.modalName = new ReactiveVar('');
	instance.autorun(function() {
		FlowRouter.watchPathChange();
		var modal = FlowRouter.getQueryParam('modal');
		instance.modalName.set(modal);
//		__modal.set(modal);
	});
});

TmplBody.helpers({
	simpleProp: "simple prop",
	makeDataForModal: function() {
		var tmpl = Template.instance();
		var name = tmpl.modalName.get();
		if (name) {
			name = 'foo_' + name;
		}
		return { modalName: name };
	},
});

Template.modal.onRendered(function() {
	this.$el = this.$('#modal');
	console.log(this.$el);
});

Template.modal.helpers({
	makeDataForContext: function() {
		var result = { foo: "foo value" };
		return result;
	}
});

Template.foo_clients_form.onCreated(function() {
	console.log('form', this.data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment