Coder Social home page Coder Social logo

brettle / iron-layout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iron-meteor/iron-layout

0.0 2.0 0.0 171 KB

Dynamic layout with support for rendering dynamic templates into regions.

License: MIT License

HTML 6.69% JavaScript 93.31%

iron-layout's Introduction

Iron.Layout

Dynamic layout with support for rendering dynamic templates into regions.

Iron.Layout is the page rendering engine for Iron.Router. Layouts can also be used independently for composing templates. For example, your app might have a standard dialog box layout and you want to populate content dynamically into the dialog box depending upon what kind of dialog it is.

Reusing Templates with a Layout

<template name="DialogBox">
  <div id="header">
    {{> yield "header"}}
  </div>
  
  <div id="main">
    {{> yield}}
  </div>
  
  <div id="footer">
    {{> yield "footer"}}
  </div>
</template>

<template name="SomeDialog">
  {{#Layout template="DialogBox" data=getSomeDataContext}}
    {{#contentFor "header"}}
      <h1>My Header</h1>
    {{/contentFor}}
    
    <p>
      The main content goes here.
    </p>
    
    {{#contentFor "footer"}}
      Footer content goes here.
    {{/contentFor}}
  {{/Layout}}
</template>

From JavaScript

<body>
  <div id="optional-container">
  </div>
</body>
if (Meteor.isClient) {
  Meteor.startup(function () {
    layout = new Iron.Layout({/* template: 'MyLayout', data: dataFunction */ });
    
    // insert the layout with an optinoal container element
    layout.insert({el: '#optional-container'});
    
    // set the template for the layout
    layout.template('DialogBox');
    
    // set the data context for the layout
    layout.data({title: 'Some Layout Title'});
    
    // render MainTemplate into the main region of the layout
    layout.render('MainTemplate');
    
    // render the MyHeader template to the 'header' region of the layout.
    layout.render('MyHeader', {to: 'header'});
    
    // render the MyFooter template to the 'footer' region of the layout. Also set a custom data context for the region.
    layout.render('MyFooter', {to: 'footer', data: {title: 'Custom footer data context'}});
  });
}

Rendering Transactions

if (Meteor.isClient) {
  Meteor.startup(function () {
    layout = new Iron.Layout({template: 'DialogBox'});
    
    // insert the layout with an optinoal container element
    layout.insert({el: '#optional-container'});
    
    // start recording which regions have been rendered into
    layout.beginRendering();
    
    // render MainTemplate into the main region of the layout
    layout.render('MainTemplate');
    
    // render the MyHeader template to the 'header' region of the layout.
    layout.render('MyHeader', {to: 'header'});
    
    // render the MyFooter template to the 'footer' region of the layout. Also set a custom data context for the region.
    layout.render('MyFooter', {to: 'footer', data: {title: 'Custom footer data context'}});
    
    // force a Deps.flush and get an object of
    // regions that have been rendered. In this case:
    // => {"main": true, "header": true, "footer": true}
    var renderedRegions = layout.endRendering();
  });
}

iron-layout's People

Contributors

avital avatar cmather avatar tmeasday avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.