Answers.Body: <p>If you want to set entry to a new value if <code>entry.title</code> is undefined or 0 length, try this:</p>
  
  <pre><code>{% if !(entry is defined and entry.title is defined and entry.title|length) %}
      {% set entry = craft.entries.section('sectionname').slug(craft.request.segment(2)).first() %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T05:36:31.423Z
Answers.LastActivityDate: 2014-06-27T05:36:31.423Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <p>Since Craft 2.6 you can do this cleanly with the <code>??</code> null-coalescing operator:</p>
  
  <pre><code>{% if not (entry.title ?? false) %}
    ...
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-17T03:39:18.953Z
Answers.LastActivityDate: 2017-02-17T03:39:18.953Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <p>I've had luck using "is defined" before using other logic operators.</p>
  
  <p>This should do it:</p>
  
  <pre><code>{% if entry.title is defined and entry.title | length == 0 %}
      {% set entry = craft.entries.section('sectionname').slug(craft.request.segment(2)).first() %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T05:36:28.390Z
Answers.Text: I think you want to set `entry` to the new value if `entry.title` is not defined or is 0 length. Which is not what this code does.
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T14:01:41.013Z
Answers.Text: You're right. I ended up using something slightly different in practice.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T06:10:11.430Z
Answers.LastActivityDate: 2014-06-26T06:10:11.430Z
Answers.UserDisplayName: Coppa
Body: <p>With dev mode on, I'm getting a warning there is no entry.title, which I know about already because that's what I'm testing for:</p>
  
  <pre><code>{% if entry.title | length == 0 %}
      {% set entry = craft.entries.section('sectionname').slug(craft.request.segment(2)).first() %}
  {% endif %}
  </code></pre>
  
  <p>Is there a way to test for a variable without dev mode triggering this notice?</p>
  
Tags: <conditional><variable><devmode>
Title: Avoid notice of variable's not being set within dev mode
ThreadText: # Avoid notice of variable's not being set within dev mode
  
  (Asked by: username_0 on 2014-06-26)
  
  With dev mode on, I'm getting a warning there is no entry.title, which I know about already because that's what I'm testing for:
  
  ```
  {% if entry.title | length == 0 %}
      {% set entry = craft.entries.section('sectionname').slug(craft.request.segment(2)).first() %}
  {% endif %}
  
  ```
  
  Is there a way to test for a variable without dev mode triggering this notice?
  
  **Tags:** conditional, variable, devmode
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2014-06-26. Score: 12 | Accepted answer
  
  I've had luck using "is defined" before using other logic operators.
  
  This should do it:
  
  ```
  {% if entry.title is defined and entry.title | length == 0 %}
      {% set entry = craft.entries.section('sectionname').slug(craft.request.segment(2)).first() %}
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_1**: I think you want to set `entry` to the new value if `entry.title` is not defined or is 0 length. Which is not what this code does.  
  > **username_0**: You're right. I ended up using something slightly different in practice.  
  
  ---
  
  ### Answer by username_1 on 2014-06-27. Score: 5
  
  If you want to set entry to a new value if `entry.title` is undefined or 0 length, try this:
  
  ```
  {% if !(entry is defined and entry.title is defined and entry.title|length) %}
      {% set entry = craft.entries.section('sectionname').slug(craft.request.segment(2)).first() %}
  {% endif %}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2017-02-17. Score: 3
  
  Since Craft 2.6 you can do this cleanly with the `??` null-coalescing operator:
  
  ```
  {% if not (entry.title ?? false) %}
    ...
  
  ```
  
  
  ---
  
  