Answers.Body: <p>You could also do it based on segments:</p>
  
  <pre><code>{% set segment1 = craft.request.segment(1) %}
  
  {% if segment1 == 'blah' %}
      do something
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T15:41:16.660Z
Answers.Text: Thanks, this worked. As Kaspar mentioned above, because it is in the _layout template this is a better approach. Is there a way to set multiple values in the 'blah' part? I'd like to do this for a few different sections.
Answers.UserDisplayName: Steve Rowland
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T16:36:27.977Z
Answers.Text: You can use `getSegments` then call each segment the same just changing the segment number in the example I gave you.
Answers.UserDisplayName: Mark Busnelli Jr
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T16:36:54.290Z
Answers.Text: Let me know if you need more info
Answers.UserDisplayName: Mark Busnelli Jr
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T11:22:26.760Z
Answers.Text: Thanks for the feedback Mark. So would I use the following to set each segment? {% set segment1 = craft.request.segment(1) %}{% if segment1 == 'blog' %}white-nav-bg{% elseif segment1 == 'ourWork' %}white-nav-bg{% endif %}
Answers.UserDisplayName: Steve Rowland
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T11:24:49.053Z
Answers.Text: Actually, I've just figured it out and the following code works: {% set segment1 = craft.request.segment(1) %}{% if segment1 == 'blog' %}white-nav-bg{% elseif segment1 == 'our-work' %}white-nav-bg{% endif %} I'll update the question with the code that worked based on your answer
Answers.UserDisplayName: Steve Rowland
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-16T14:06:39.613Z
Answers.LastActivityDate: 2015-09-16T21:05:25.957Z
Answers.LastEditDate: 2015-09-16T21:05:25.957Z
Answers.UserDisplayName: Mark Busnelli Jr
Answers.Body: <p>There are many possibilities for this.</p>
  
  <p>One of them is to listen to the section handle if you want it to be triggered only on the blog template:</p>
  
  <pre><code>{% if entry.section.handle == 'blog' %}your-class{% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T08:08:58.167Z
Answers.Text: Hi Kaspar, huge apologies for delayed response. Thank you for your helpful answer. It has partially worked but I am getting a template error on the Blog page now "Variable "entry" does not exist" - I'm assuming this is because my code is in the _layout template before I have set entry?
Answers.UserDisplayName: Steve Rowland
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T09:41:15.310Z
Answers.Text: Yep. If you need this to be in the layout you can define a entry variable (Altough this isn't very pretty). `{% if entry is undefined %}{% set entry == x%}{% endif %}` But since you use it in layout I would go for the solution with the segments.
Answers.UserDisplayName: KSPR
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-16T11:42:05.640Z
Answers.LastActivityDate: 2015-09-16T11:42:05.640Z
Answers.UserDisplayName: KSPR
Body: <p>I'm trying to create a conditional logic so that the class 'white-nav-bg' is added to the  element on the 'blog' section entries only.</p>
  
  <p>Below is the code I'm currently using to try and achieve this with a logic tag but it is adding the 'white-nav-bg' class to all pages on the site rather than just the blog section entry pages.</p>
  
  <pre><code>&lt;nav class="navbar navbar-default navbar-fixed-top
    {% for entry in craft.entries.section('blog').limit(1) %}
      {% if entry.type.handle == 'post' %}white-nav-bg{% endif %}
    {% endfor %}"&gt;
  </code></pre>
  
  <p>This code is in the '_layout.html' file, hence needing to figure out how to do conditional logic tags rather than adding the code differently in the blog template files.</p>
  
  <p>After much time looking through Craft documentation I can't seem to find an example of how to do this. Any help would be gratefully received.</p>
  
  <p>UPDATE:</p>
  
  <p>Following helpful answers I have come to the following code, which works and allows me to define multiple sections to have the 'white-nav-bg' class.</p>
  
  <pre><code>{% set segment1 = craft.request.segment(1) %}
  &lt;nav class="navbar navbar-default navbar-fixed-top
    {% if segment1 == 'blog' %}
      white-nav-bg
    {% elseif segment1 == 'our-work' %}
      white-nav-bg
    {% endif %}"&gt;
  </code></pre>
  
Tags: <entry><sections><conditional><logic>
Title: Conditional logic to add class for specific section entries
ThreadText: # Conditional logic to add class for specific section entries
  
  (Asked by: username_0 on 2015-09-16)
  
  I'm trying to create a conditional logic so that the class 'white-nav-bg' is added to the element on the 'blog' section entries only.
  
  Below is the code I'm currently using to try and achieve this with a logic tag but it is adding the 'white-nav-bg' class to all pages on the site rather than just the blog section entry pages.
  
  ```
  <nav class="navbar navbar-default navbar-fixed-top
    {% for entry in craft.entries.section('blog').limit(1) %}
      {% if entry.type.handle == 'post' %}white-nav-bg{% endif %}
    {% endfor %}">
  
  ```
  
  This code is in the '\_layout.html' file, hence needing to figure out how to do conditional logic tags rather than adding the code differently in the blog template files.
  
  After much time looking through Craft documentation I can't seem to find an example of how to do this. Any help would be gratefully received.
  
  UPDATE:
  
  Following helpful answers I have come to the following code, which works and allows me to define multiple sections to have the 'white-nav-bg' class.
  
  ```
  {% set segment1 = craft.request.segment(1) %}
  <nav class="navbar navbar-default navbar-fixed-top
    {% if segment1 == 'blog' %}
      white-nav-bg
    {% elseif segment1 == 'our-work' %}
      white-nav-bg
    {% endif %}">
  
  ```
  
  **Tags:** entry, sections, conditional, logic
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-09-16. Score: 1 | Accepted answer
  
  You could also do it based on segments:
  
  ```
  {% set segment1 = craft.request.segment(1) %}
  
  {% if segment1 == 'blah' %}
      do something
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks, this worked. As Kaspar mentioned above, because it is in the _layout template this is a better approach. Is there a way to set multiple values in the 'blah' part? I'd like to do this for a few different sections.  
  > **username_1**: You can use `getSegments` then call each segment the same just changing the segment number in the example I gave you.  
  > **username_1**: Let me know if you need more info  
  > **username_0**: Thanks for the feedback Mark. So would I use the following to set each segment? {% set segment1 = craft.request.segment(1) %}{% if segment1 == 'blog' %}white-nav-bg{% elseif segment1 == 'ourWork' %}white-nav-bg{% endif %}  
  > **username_0**: Actually, I've just figured it out and the following code works: {% set segment1 = craft.request.segment(1) %}{% if segment1 == 'blog' %}white-nav-bg{% elseif segment1 == 'our-work' %}white-nav-bg{% endif %} I'll update the question with the code that worked based on your answer  
  
  ---
  
  ### Answer by username_2 on 2015-09-16. Score: 1
  
  There are many possibilities for this.
  
  One of them is to listen to the section handle if you want it to be triggered only on the blog template:
  
  ```
  {% if entry.section.handle == 'blog' %}your-class{% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Hi Kaspar, huge apologies for delayed response. Thank you for your helpful answer. It has partially worked but I am getting a template error on the Blog page now "Variable "entry" does not exist" - I'm assuming this is because my code is in the _layout template before I have set entry?  
  > **username_2**: Yep. If you need this to be in the layout you can define a entry variable (Altough this isn't very pretty). `{% if entry is undefined %}{% set entry == x%}{% endif %}` But since you use it in layout I would go for the solution with the segments.  
  
  ---
  
  