Dariusz Sikorski
Dariusz Sikorski

Reputation: 4407

Can't set body class with Template.helpers

To add dynamic class for body tag i used:

<body class="{{bodyClass}}"><!-- this remains uncompiled -->
  {{bodyClass}} <!-- this renders to "blue" -->
</body>

and helper code:

Template.body.helpers({
  bodyClass: function(){
    return 'blue';
  }
});

As result {{bodyClass}} Inside body content is compiled to blue as expected, but the <body class="{{bodyClass}}"> remains uncompiled.

[edit] Ps. I'm using lates meteor 1.3

Upvotes: 0

Views: 152

Answers (2)

Adam Moisa
Adam Moisa

Reputation: 1383

In the template right at the begging (or anywhere in the template really) you can simply do:

<style type="text/css">
    body: blue;
</style>

Use !important if you need to.

Upvotes: 0

Luna
Luna

Reputation: 1178

Try onRendered with jQuery addClass

Template.templateName.onRendered(function (){
    $('body').addClass('blue')
});

Upvotes: 1

Related Questions