Answers.Body: <p>You both are correct.</p>
  <p>I started experimenting with and without .one(). But the real problem was that the person i was trying to help did not fill out all the required fields and thus the errors were thrown and the behaviour threw me off...</p>
  <p>Sorry for this and thank you for all your help and tips</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-09T12:27:17.053Z
Answers.LastActivityDate: 2022-08-09T12:27:17.053Z
Answers.UserDisplayName: Leonardo
Answers.Body: <p>If the <code>linkedEntry</code> field is empty, then <code>category.linkedPage.one()</code> will evaluate to <code>null</code>, so you should always add a condition to check that a value exists before calling a method on it.</p>
  <pre><code>{% set linkedEntry = category.linkedPage.one() %}
  
  {# Explicit syntax. #}
  {% if linkedEntry is not null %}
      {% set handle = linkedEntry.section.handle %}
  {% endif %}
  
  {# Alternative, simpler syntax. #}
  {% if linkedEntry %}
      {% set handle = linkedEntry.section.handle %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-02T11:48:43.140Z
Answers.LastActivityDate: 2022-08-02T11:48:43.140Z
Answers.UserDisplayName: Ben Croker
Answers.Body: <p>You haven't executed your element query: <a href="https://craftcms.com/docs/4.x/element-queries.html#executing-element-queries" rel="nofollow noreferrer">https://craftcms.com/docs/4.x/element-queries.html#executing-element-queries</a></p>
  <p>(If you attempted to do this in Craft 3 it would have given you a slapped wrist by logging a deprecation warning in the control panel, but would have executed the element query for you anyway). Craft 4 is more strict about ensuring that you execute your element queries yourself. It's an important concept to understand, because otherwise you can blindly end up putting element queries inside loops, which is terrible for performance.</p>
  <pre><code>{% set linkedEntry = category.linkedPage.one() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-02T09:44:33.467Z
Answers.LastActivityDate: 2022-08-02T09:44:33.467Z
Answers.UserDisplayName: James Smith
Body: <p>Maybe Craft 4 is playing games with me but im stuck on this problem:</p>
  <ul>
  <li><code>linkedEntry</code> is an entry field which is limited to 1 entry.</li>
  </ul>
  <p>This outputs the section handle correctly</p>
  <pre class="lang-php prettyprint-override"><code> {% set linkedEntry = category.linkedPage %}
   {% dd(linkedEntry.section.handle) %}
  </code></pre>
  <p>This tells me that the <code>section()</code> function is called without an parameter</p>
  <pre class="lang-php prettyprint-override"><code>{% set linkedEntry = category.linkedPage %}
  {% if linkedEntry.section.handle === 'exampleHandle' %}
  </code></pre>
  <p>And this tells me that i cant call the attribute <code>section</code> on null</p>
  <pre class="lang-php prettyprint-override"><code>{% if category.linkedPage.section.handle === 'exampleHandle' %}
  </code></pre>
  <p>Am i missing something thats new in Craft 4?</p>
  <p>Greetings</p>
  
Tags: <templating><entry><sections><craft4>
Title: Get section handle of an entry inside of an EntryField
ThreadText: # Get section handle of an entry inside of an EntryField
  
  (Asked by: username_0 on 2022-08-02)
  
  Maybe Craft 4 is playing games with me but im stuck on this problem:
  
  * `linkedEntry` is an entry field which is limited to 1 entry.
  
  This outputs the section handle correctly
  
  ```php
   {% set linkedEntry = category.linkedPage %}
   {% dd(linkedEntry.section.handle) %}
  
  ```
  
  This tells me that the `section()` function is called without an parameter
  
  ```php
  {% set linkedEntry = category.linkedPage %}
  {% if linkedEntry.section.handle === 'exampleHandle' %}
  
  ```
  
  And this tells me that i cant call the attribute `section` on null
  
  ```php
  {% if category.linkedPage.section.handle === 'exampleHandle' %}
  
  ```
  
  Am i missing something thats new in Craft 4?
  
  Greetings
  
  **Tags:** templating, entry, sections, craft4
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2022-08-09. Score: 0 | Accepted answer
  
  You both are correct.
  
  I started experimenting with and without .one(). But the real problem was that the person i was trying to help did not fill out all the required fields and thus the errors were thrown and the behaviour threw me off...
  
  Sorry for this and thank you for all your help and tips
  
  
  ---
  
  ### Answer by username_1 on 2022-08-02. Score: 2
  
  If the `linkedEntry` field is empty, then `category.linkedPage.one()` will evaluate to `null`, so you should always add a condition to check that a value exists before calling a method on it.
  
  ```
  {% set linkedEntry = category.linkedPage.one() %}
  
  {# Explicit syntax. #}
  {% if linkedEntry is not null %}
      {% set handle = linkedEntry.section.handle %}
  {% endif %}
  
  {# Alternative, simpler syntax. #}
  {% if linkedEntry %}
      {% set handle = linkedEntry.section.handle %}
  {% endif %}
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2022-08-02. Score: 1
  
  You haven't executed your element query: <https://craftcms.com/docs/4.x/element-queries.html#executing-element-queries>
  
  (If you attempted to do this in Craft 3 it would have given you a slapped wrist by logging a deprecation warning in the control panel, but would have executed the element query for you anyway). Craft 4 is more strict about ensuring that you execute your element queries yourself. It's an important concept to understand, because otherwise you can blindly end up putting element queries inside loops, which is terrible for performance.
  
  ```
  {% set linkedEntry = category.linkedPage.one() %}
  
  ```
  
  
  ---
  
  