Skip to content

andrejsm/meteor-template-destruct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Destruct Blaze templates

Easily destruct Blaze template functions

Installation

meteor add ouk:template-destruct

This package adds new function destructTemplate to global scope. The function takes one argument and returns object with bound template functions.

Template functions ready for destructuring:

onCreated
onRendered
onDestroyed
helpers
events

Usage example

templates/news/section.html

<template name="newSection">
  <h1 class="js-click-on-title">{{title}}</h1>
</template>

templates/news/section.js

let { onCreated, helpers, events } = destructTemplate('newsSection')

onCreated(function() {
  this.title = 'News'
})

helpers({
  title() {
    return `${Template.instance().title} section`
  }
})

events({
  'click .js-click-on-title'(e, t) {
    e.target.classList.toggle('is-active')
  }
})

This package gives you an alternative approach to this:

Template.newsSection.onCreated(...)
Template.newsSection.helpers(...)

// or

let template = Template.newsSection

template.onCreated(...)
template.helpers(...)

About

Destructuring helper for Blaze templates

Resources

Stars

Watchers

Forks

Packages

No packages published