Change css based on Collection value

In the page i am able to display {{ type }] from the database , but i want to change the css class of the div if the value of type is dog for example.

This should be easy in Meteor but i don’t know how could i do that :confused:

Items= new Mongo.Collection('items'),

<template name="Details">
    <div>
        {{ type }}
    </div>
</template>
<template name="Details">
  <div class="{{classHelper type}}">
  </div>
</template>

Template.Details.helpers({
  classHelper (type) {
    if (type === 'dog') {
      return 'dog-class';
    }
  }
});
1 Like

@vigorwebsolutions thanks for super-fast answer. I love the Meteor community! :relaxed:

1 Like

@vigorwebsolutions can you do this without using templateHelpers? Using reactiveVar or reactiveDict for example.

You would still need a helper of some kind to get the reactiveVar or reactiveDict value into the template.