Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dynamic Inclusion example #1278

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/dynamic_inclusion/client/example.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.panel {
background:#eee;
padding:2em;
}

.area {
border:1px solid #aaa;
padding:2em;
}
61 changes: 61 additions & 0 deletions examples/dynamic_inclusion/client/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

<template name="default">

<h1>This is our main wrapper which usually defines the navigation bar, footer, etc</h1>

<nav>
<a href="/dashboard">Dashboard</a>
<a href="/settings">Settings</a>
</nav>

<div>
{{> yield region="body"}}
</div>

</template>


<template name="dashboard">
<div class="panel">
This is our dashboard template
</div>
</template>


<template name="settings">

<div class="panel">
<div>
<a href="/settings/profile">Profile</a>
<a href="/settings/account">Account</a>
<a href="/settings/billing">Billing</a>
</div>

<div class="area">
{{ > yield}}
</div>

</div>

</template>


<template name="profile">

<strong>This is the profile content</strong>

</template>


<template name="billing">

<strong>This is the billing content</strong>

</template>

<template name="account">

<strong>This is the account content</strong>

</template>

19 changes: 19 additions & 0 deletions examples/dynamic_inclusion/client/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@




Template.settings.helpers({


getTemplate: function() {

var w = window.location.href.split("/");

return w[4];
}

});




72 changes: 72 additions & 0 deletions examples/dynamic_inclusion/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Dynamic Inclusion Example
*
* This examples shows how to dynamically include templates within a wrapper in second level
* routes using only Iron Router
*
* Author: http://github.com/flyandi
*/


/**
* Configure the router with the base template
*/

Router.configure({
layoutTemplate: 'default'
});


/**
* This is our first content area
*/

Router.route('/dashboard', {

yieldTemplates: {
'dashboard': {to: 'body'}
},

});

/**
* This is our second route that has the second level content areas
*/


Router.route("/settings", function() {

this.redirect("/settings/profile");

});


/**
* Here we registering our second level content areas
*/

['profile', 'billing', 'account'].forEach(function(path) {


Router.route('/settings/' + path, {

yieldTemplates: {
'settings': {to: 'body'}
},

template: path,

});

});


/**
* This is just for convience so we always start with our first route
*/

Router.route('/', function() {
this.redirect("/dashboard");
});