#70 Math in HTMLBars

Tip

Guest Tip by Robert from ShipShape
Sometimes you just need to do a quick calculation, like adding 1 to an index, and you do not want to define a computed property in your JS file just for that.
For quick and dirty arithmetic in your templates, you can use ember-math-helpers.
Just install it like any addon

Then for a simple case like adding one to the index, you could do:

It also supports multiple arguments and is composable, so you can do things like:

ember-math-helpers supports most basic math and all the options can be found in the README at https://github.com/shipshapecode/ember-math-helpers
Credits & Links
Ship Shape

Ship Shape
Ship Shape is a Washington D.C. based Ember consultancy. We leverage Ember.js, and all the latest technologies, to create truly ambitious applications.

Share A Tip

Email me at emad@emberdaily.tips if you have a good ember tip.
If you are enjoying my daily tips please spread the word with this one-click tweet.
If you do NOT like the tips then please reply to this email and let me know how I can improve them.

Published by

Emad Ibrahim

Author of asp .net MVC & TDD, entrepreneur, passionate technologist, programmer and productivity nut. more at http://t.co/oSJXPvzu