Answers.Body: <p>You need to pass the entry module (or just parts of the entry module, e.g. entry.title) as a parameter when calling the macro in your template.</p>
  <p>Macro:</p>
  <pre><code>{% macro drawEntryTitle(entry) %}
    &lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
  {% endmacro %}
  </code></pre>
  <p>Call macro:</p>
  <pre><code>{{ macro.drawEntryTitle(entry) }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-10T19:54:09.897Z
Answers.LastActivityDate: 2022-08-10T19:54:09.897Z
Answers.UserDisplayName: fr-haus
Body: <p><strong>Scenario</strong>:</p>
  <p>I am creating a twig macro to display a navigation menu.</p>
  <p>Said menu will be displayed on any page (home, blog, multiple landing pages, ...)</p>
  <p>In some cases we will be visiting a specific entry of a section (for example in the blog).</p>
  <p><strong>What I want:</strong></p>
  <p>I want to be able to access a specific field of the current entry if it is defined.</p>
  <p>For example, access blog section specialField.</p>
  <p><strong>What I am trying:</strong></p>
  <p>I am trying to access it with <code>entry.specialField</code></p>
  <p><strong>The problem:</strong></p>
  <p><code>entry.specialField</code> is not defined when I am in the macro (even if I am visiting an entry that has the specialField).</p>
  <p><strong>The question:</strong></p>
  <p>How can I access this, inside the macro?</p>
  <p><strong>For people who have used WordPress:</strong></p>
  <p>This would be equivalent to something like getting a <em>meta value</em> from the current <em>post</em>. It can be achieved easily with <code>global $post</code>.</p>
  
Tags: <entry>
Title: Get current entry field from inside a macro
ThreadText: # Get current entry field from inside a macro
  
  (Asked by: username_0 on 2022-08-10)
  
  **Scenario**:
  
  I am creating a twig macro to display a navigation menu.
  
  Said menu will be displayed on any page (home, blog, multiple landing pages, ...)
  
  In some cases we will be visiting a specific entry of a section (for example in the blog).
  
  **What I want:**
  
  I want to be able to access a specific field of the current entry if it is defined.
  
  For example, access blog section specialField.
  
  **What I am trying:**
  
  I am trying to access it with `entry.specialField`
  
  **The problem:**
  
  `entry.specialField` is not defined when I am in the macro (even if I am visiting an entry that has the specialField).
  
  **The question:**
  
  How can I access this, inside the macro?
  
  **For people who have used WordPress:**
  
  This would be equivalent to something like getting a *meta value* from the current *post*. It can be achieved easily with `global $post`.
  
  **Tags:** entry
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-08-10. Score: 1 | Accepted answer
  
  You need to pass the entry module (or just parts of the entry module, e.g. entry.title) as a parameter when calling the macro in your template.
  
  Macro:
  
  ```
  {% macro drawEntryTitle(entry) %}
    <h1>{{ entry.title }}</h1>
  {% endmacro %}
  
  ```
  
  Call macro:
  
  ```
  {{ macro.drawEntryTitle(entry) }}
  
  ```
  
  
  ---
  
  