ostrio:templatehelpers

v2.0.1Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Meteor Template helpers

Add functionality to:

  • get/set Session - {{Session 'key' set='value'}}, {{#if Session 'key'}} ... {{/if}}
  • compare values in conditions - {{#if compare one '===' two}} ... {{/if}}
  • use underscore's functions - {{#if _ 'isString' 'one'}} ... {{/if}}
  • debug/log passed objects as a string to template - {{log this.someVal 'string' object="value"}}

Install:

meteor add ostrio:templatehelpers

Session

Get or set session value from views via Session helper

1<!-- To get value -->
2{{Session 'key'}}
3
4<!-- To set value -->
5{{Session 'key' set="new value"}}
6
7<!-- To set default value -->
8{{Session 'key' set="new value" action="setDefault"}}

log aka debug

Log arguments into browser's console, and output into template

1{{log 'val' opt='val2' opt2=variable}}

Underscore (all functions)

Execute underscore functions in template

1{{#if _ 'isString' 'one'}}
2  ...
3{{/if}}

Compare functions

Compare two values in template
1{{compare 'one' '>' 'two'}}
2{{compare 'one' 'gt' 'two'}}
3{{compare 'one' 'greaterThan' 'two'}}
4
5{{compare 'one' '>=' 'two'}}
6{{compare 'one' 'gte' 'two'}}
7{{compare 'one' 'greaterThanEqual' 'two'}}
8
9{{compare 'one' '<' 'two'}}
10{{compare 'one' 'lt' 'two'}}
11{{compare 'one' 'lessThan' 'two'}}
12
13{{compare 'one' '<=' 'two'}}
14{{compare 'one' 'lte' 'two'}}
15{{compare 'one' 'lessThanEqual' 'two'}}
16
17{{compare 'one' '===' 'two'}}
18{{compare 'one' 'is' 'two'}}
19
20{{compare 'one' '!==' 'two'}}
21{{compare 'one' 'isnt' 'two'}}
22
23{{compare 'one' '==' 'two'}}
24{{compare 'one' 'isEqual' 'two'}}
25
26{{compare 'one' '!=' 'two'}}
27{{compare 'one' 'isNotEqual' 'two'}}
28
29{{compare 'one' '&&' 'two'}}
30{{compare 'one' 'and' 'two'}}
31
32{{compare 'one' '&!' 'two'}} <!-- (a && !b) -->
33{{compare 'one' '!&' 'two'}} <!-- (!a && b) -->
34{{compare 'one' '!&!' 'two'}} <!-- (!a && !b) -->
35{{compare 'one' '!&&' 'two'}} <!-- !(a && b) -->
36{{compare 'one' 'nand' 'two'}} <!-- !(a && b) -->
37
38{{compare 'one' '||' 'two'}}
39{{compare 'one' 'or' 'two'}}
40<!-- Or statements returns real values -->
41<!-- For example you have one falsy value and another not -->
42<!-- Truthy value will be returned then (as in real JS-script) -->
43
44{{compare 'one' '|!' 'two'}} <!-- (a || !b) -->
45{{compare 'one' '!|' 'two'}} <!-- (!a || b) -->
46{{compare 'one' '!|!' 'two'}} <!-- (!a || !b) -->
47{{compare 'one' '!||' 'two'}} <!-- !(a || b) -->
48{{compare 'one' 'nor' 'two'}} <!-- !(a || b) -->
49
50{{compare 'one' 'xor' 'two'}} <!-- ((a && !b) || (!a && b)) -->
51{{compare 'one' 'nxor' 'two'}} <!-- !((a && !b) || (!a && b)) -->
Compare many to many
1{{compare 1 '>' 2 '&&' 5 '<' 8}}
2{{compare 1 '>' 2 '||' 5 '<' 8}}
3{{compare first '||' second '||' third}}
4{{compare first '&&' second '&&' third}}
5{{compare first '&&' second '||' third}}
6<!-- Any combinations will work, above just basic examples -->
Compare one value to many (any of.. match)
1{{compare 'one' '>' 'two|one|three|four|five'}}
2{{compare 'one' '>=' 'two|one|three|four|five'}}
3{{compare 'one' '<' 'two|one|three|four'}}
4{{compare 'one' '<=' 'two|one|three'}}
5{{compare 'one' '===' 'two|one'}}
6{{compare 'one' '!==' 'two|one|three'}}
7{{compare 'one' '==' 'two|one|three|four'}}
8{{compare 'one' '!=' 'two|one|three|four'}}
9{{compare 'one' '&&' 'two|one|three|four'}}