Using a Lightswitch to insert a class on a body's tag I'm trying to use a Lightswitch field to insert a class on my body tag if the field is turned on. 

What would be a good Twig template code to do this?



Edit 1:

Thanks for answering, guys. I still couldn't manage to do it, though. My lightswitch field handle is named whiteText. If I do this: 

&lt;body class='{% if whiteText('1') %}white{% endif %}'&gt; 


it'll just say: 


  The function "whiteText" does not exist


(which I assume seems logical for you guys, but not for me). 

And if I use entry.whiteText it'll say:


  Craft\EntryModel and its behaviors do not have a method or closure
  named "whiteText".


I should also have some kind of "else" in the code, to output a clean -tag if the lightswitch is not switched on. 



Edit 2:

I have now set up a global field. If I do {{ globalfieldhandle.lightswitchfieldhandle }} it outputs 0, even on the craft entry section I have it switched on (a single). 

I need a way to make it say "1" if the lightswitch is turned on on the entry, and some help with the code to add a class on the body tag, and also the code for doing nothing if its not turned on.

Anyone?

The first answer to my question: 

&lt;body class='{% if lightswitch_field_handle %}class_name{% endif %}'&gt;


seems like the right direction, but is it missing something?
Lightswitch fields save an integer to the database:

This integer can be checked just like a boolean, with Twigs if-tag:

&lt;body class='{% if lightswitch_field_handle %}class_name{% endif %}'&gt;



  1 = true  = on
  0 = false = off


.

Twig has also a ternary operator which is similar to php's ternary operator:

&lt;body class="{{ lightswitch_field_handle ? 'class_name' }}"&gt;

&lt;body class="{{ lightswitch_field_handle ? 'class_name' : 'alt_class_name' }}"&gt;




Answer to Edit 1:

Your example doesn't work because you aren't comparing: if value == 1, you are checking a function: if function(param) == true. Check out the Twig if documentation for more examples.

If entry.whiteText doesn't work, your section doesn't have such a field. If you added it to your main template, you should check if the field is defined.