Answers.Body: <p>You can use the same lightswitch field on both of your channel sections.</p>
  
  <p>But I wouldn't use an EntryModel in the <code>_layout.html</code> (assuming that's a template you use to extend your actual entry and index templates with).</p>
  
  <p>You probably have two different <code>_entry.html</code> templates for your sections "project" and "events". Define a variable in these if your condition (lightswitch) is true:</p>
  
  
  
  <pre class="lang-twig prettyprint-override"><code>{% extends "_layout" %}
  
  {% if entry.whiteLogoText %}
      {% set bodyClass = 'white' %}
  {% endif %}
  
  {% block content %}
  {% endblock %}
  </code></pre>
  
  <p>This is how your <code>_layout.html</code> should look like:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% if bodyClass is defined %}
      &lt;body class="otherBodyClasses {{ bodyClass }}"&gt;
  {% else %}
      &lt;body class="otherBodyClasses"&gt;
  {% endif %}
  
  &lt;main class="page" role="main"&gt;
      {% block content %}
      {% endblock %}
  &lt;/main&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>Or with the ternary syntax:</p>
  
  <pre class="lang-twig prettyprint-override"><code>&lt;body class="otherBodyClasses {{ bodyClass is defined ? bodyClass }}"&gt;
  </code></pre>
  
  <p>.</p>
  
  <p><strong><em>Edit:</em></strong></p>
  
  <p>You can additionally set that <code>bodyClass</code> variable in other templates using different conditionals:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% if myGlobalSetHandle.whiteLogoTextForProjectsEntries %}
      {% set bodyClass = 'white' %}
  {% endif %}
  </code></pre>
  
  <p>or (based on my latest assumptions on what you wanna do):</p>
  
  <pre class="lang-twig prettyprint-override"><code>{# Define var before the for loop #}
  {% set bodyClass = '' %}
  
  {# Check if `whiteLogoText` is set on any "project" entry #}
  {% for project in craft.entries.section('projects') %}
      {% if project.whiteLogoText %}
          {% set bodyClass = 'white' %}
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>With this last code example you have to define the variable before the loop to make it accessible outside of it. Because you will always have a <code>bodyClass</code> defined then, change the conditional in your <code>_layout.html</code> like this:</p>
  
  <pre class="lang-twig prettyprint-override"><code>&lt;body class="otherBodyClasses {{ bodyClass is defined and != '' ? bodyClass }}"&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T20:40:07.903Z
Answers.Text: Thanks alot for helping out Christian. Its a bit more complicated: On the 'events' section "landing page" (index.html) this works fine. But on the 'projects' section I use a feed of entries to print the projects. I would like to define the lightswitch field on an unique project entry, and then output it with a feed of entries. Does this make sense?
Answers.UserDisplayName: osh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T21:02:31.457Z
Answers.Text: Hmmm.. don't know if I get you right. Basically you want one lightswitch field, that is responsible for all of your `_entry.html` templates for that "projects" section?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T21:04:56.823Z
Answers.Text: Other option: you could have that field on each of you "projects" entries in the CP and then check in your template if it is set to true on any of these?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T21:16:53.960Z
Answers.Text: I have a landing page for 'events' (index.html), which is a single section. Telling this to get body class=white works fine, with the lightswitch field added to its field layout. I also have a landing page for 'projects' (index.html). This page (a single) feeds a bunch of projects (a channel). If its turned on in one of the entries in the feed, it should do body class=white. Just to make clear: None of this happens on _entry level, both instances are index.html. The body class=white class makes my menus links turn white, rather than black, if that makes any sense. Thanks for your patience!
Answers.UserDisplayName: osh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T21:20:18.030Z
Answers.Text: See the last example, this should work on your "projects" `index.html`.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T21:30:14.063Z
Answers.Text: Corrected a code error that printed 'bodyClass' instead of 'white' (the value of `bodyClass`)!
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T21:37:40.567Z
Answers.Text: @Oyvind could you please copy some of that additional info you provided to your question text?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-16T11:24:55.053Z
Answers.Text: @Oyvind it'd nice to hear if this ended up working for you!
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-27T14:12:24.963Z
Answers.Text: @osh nice to see you're back and I hope everything's good so far. Could you please do me a favor and go through your Q/As and respond to open questions / accept helpful answers? Thanks!
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T20:01:35.507Z
Answers.LastActivityDate: 2014-07-15T21:28:45.350Z
Answers.LastEditDate: 2014-07-15T21:28:45.350Z
Answers.UserDisplayName: carlcs
Body: <p>I'm using a lightswitch field to add a class to my html document body-tag. The field is added to a section  with a handle named "events". </p>
  
  <p>To make this happen, I do this in my _layout.html:</p>
  
  <pre><code>{% if entry.whiteLogoText %}
      &lt;body class="white"&gt;
  {% else %}
      &lt;body&gt;
  {% endif %}
  </code></pre>
  
  <p>Now I also want to use such a lightswitch for entries of a different section (with a field handle named 'projects').</p>
  
  <p>Should I make a new lightswitch field for this particular section, and if so, how should I print it?</p>
  
  <p>I wanna make sure I don't get two <code>&lt;body&gt;</code>-tags.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-15T19:37:27.880Z
Comments.Text: Can you clarify/add some context to this?  You mention a handle named events, but I don't see that referenced in your template code. and I'm not sure what "-tag"  is you're referring to.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-15T20:06:55.617Z
Comments.Text: Edited post, fixed the "-tag" display issue.
Comments.UserDisplayName: Lindsey D
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-15T20:08:18.453Z
Comments.Text: Lol, @Lindsey. Must have saved my edit half a second after you did yours :)
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-15T20:08:57.810Z
Comments.Text: @Christian Photo finish!
Comments.UserDisplayName: Lindsey D
Tags: <conditional><lightswitch>
Title: Two different lightswitches to add class on body tag
ThreadText: # Two different lightswitches to add class on body tag
  
  (Asked by: username_0 on 2014-07-15)
  
  I'm using a lightswitch field to add a class to my html document body-tag. The field is added to a section with a handle named "events".
  
  To make this happen, I do this in my \_layout.html:
  
  ```
  {% if entry.whiteLogoText %}
      <body class="white">
  {% else %}
      <body>
  {% endif %}
  
  ```
  
  Now I also want to use such a lightswitch for entries of a different section (with a field handle named 'projects').
  
  Should I make a new lightswitch field for this particular section, and if so, how should I print it?
  
  I wanna make sure I don't get two `<body>`-tags.
  
  **Tags:** conditional, lightswitch
  
  > **Comments:**
  > **username_1**: Can you clarify/add some context to this?  You mention a handle named events, but I don't see that referenced in your template code. and I'm not sure what "-tag"  is you're referring to.  
  > **username_2**: Edited post, fixed the "-tag" display issue.  
  > **username_3**: Lol, @username_2. Must have saved my edit half a second after you did yours :)  
  > **username_2**: @Christian Photo finish!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2014-07-15. Score: 1
  
  You can use the same lightswitch field on both of your channel sections.
  
  But I wouldn't use an EntryModel in the `_layout.html` (assuming that's a template you use to extend your actual entry and index templates with).
  
  You probably have two different `_entry.html` templates for your sections "project" and "events". Define a variable in these if your condition (lightswitch) is true:
  
  ```twig
  {% extends "_layout" %}
  
  {% if entry.whiteLogoText %}
      {% set bodyClass = 'white' %}
  {% endif %}
  
  {% block content %}
  {% endblock %}
  
  ```
  
  This is how your `_layout.html` should look like:
  
  ```twig
  {% if bodyClass is defined %}
      <body class="otherBodyClasses {{ bodyClass }}">
  {% else %}
      <body class="otherBodyClasses">
  {% endif %}
  
  <main class="page" role="main">
      {% block content %}
      {% endblock %}
  </main>
  
  </body>
  
  ```
  
  Or with the ternary syntax:
  
  ```twig
  <body class="otherBodyClasses {{ bodyClass is defined ? bodyClass }}">
  
  ```
  
  .
  
  ***Edit:***
  
  You can additionally set that `bodyClass` variable in other templates using different conditionals:
  
  ```twig
  {% if myGlobalSetHandle.whiteLogoTextForProjectsEntries %}
      {% set bodyClass = 'white' %}
  {% endif %}
  
  ```
  
  or (based on my latest assumptions on what you wanna do):
  
  ```twig
  {# Define var before the for loop #}
  {% set bodyClass = '' %}
  
  {# Check if `whiteLogoText` is set on any "project" entry #}
  {% for project in craft.entries.section('projects') %}
      {% if project.whiteLogoText %}
          {% set bodyClass = 'white' %}
      {% endif %}
  {% endfor %}
  
  ```
  
  With this last code example you have to define the variable before the loop to make it accessible outside of it. Because you will always have a `bodyClass` defined then, change the conditional in your `_layout.html` like this:
  
  ```twig
  <body class="otherBodyClasses {{ bodyClass is defined and != '' ? bodyClass }}">
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks alot for helping out Christian. Its a bit more complicated: On the 'events' section "landing page" (index.html) this works fine. But on the 'projects' section I use a feed of entries to print the projects. I would like to define the lightswitch field on an unique project entry, and then output it with a feed of entries. Does this make sense?  
  > **username_3**: Hmmm.. don't know if I get you right. Basically you want one lightswitch field, that is responsible for all of your `_entry.html` templates for that "projects" section?  
  > **username_3**: Other option: you could have that field on each of you "projects" entries in the CP and then check in your template if it is set to true on any of these?  
  > **username_0**: I have a landing page for 'events' (index.html), which is a single section. Telling this to get body class=white works fine, with the lightswitch field added to its field layout. I also have a landing page for 'projects' (index.html). This page (a single) feeds a bunch of projects (a channel). If its turned on in one of the entries in the feed, it should do body class=white. Just to make clear: None of this happens on _entry level, both instances are index.html. The body class=white class makes my menus links turn white, rather than black, if that makes any sense. Thanks for your patience!  
  > **username_3**: See the last example, this should work on your "projects" `index.html`.  
  > **username_3**: Corrected a code error that printed 'bodyClass' instead of 'white' (the value of `bodyClass`)!  
  > **username_3**: @Oyvind could you please copy some of that additional info you provided to your question text?  
  > **username_3**: @Oyvind it'd nice to hear if this ended up working for you!  
  > **username_3**: @username_0 nice to see you're back and I hope everything's good so far. Could you please do me a favor and go through your Q/As and respond to open questions / accept helpful answers? Thanks!  
  
  ---
  
  