Answers.Body: <p>You won't be able to do it that way because <code>entry.field2</code> will return you the normalized field value and there is no way to trace back some object|string|variable to an unknown entry with an unknown field handle. You need to pass the handle as a second parameter in your macro</p>
  
  <pre><code>{% macro myMacro(field, fieldHandle) %}
      {{ fieldHandle }}
  {% endmacro %}
  
  myMacro(entry.field2, 'field2').
  </code></pre>
  
  <p>You could also pass the entry and a field handle instead of the field</p>
  
  <pre><code>{% macro myMacro(element, fieldHandle) %}
      {{ fieldHandle }}
      {% set value = element.getFieldValue(fieldHandle) %}
  {% endmacro %}
  
  myMacro(entry, 'field2').
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-17T14:53:07.083Z
Answers.Text: I had been passing the string in the macro, but was hoping to eliminate that as a requirment. I dig your second approach, I hadn't thought of that, but I'd be worried the loss of clarity may not be worth it in the long run. Cool all the same.
Answers.UserDisplayName: Jeremy A
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-17T14:57:49.727Z
Answers.Text: Well... You have an object and you have an index, when you pass only the elements value you can't know what the corresponding index is. However - depending on the macro you should not lose that much insight just because you pass a handle
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-17T13:22:42.447Z
Answers.LastActivityDate: 2018-04-17T13:22:42.447Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm passing entry fields into a macro and I'd like to be able to get a string of the field handle</p>
  
  <pre><code>myMacro(entry.field1)
  myMacro(entry.field2)
  
  {% macro myMacro(entry) %}
    {# I want a string of 'field1' here #}
  {% endmacro %}
  </code></pre>
  
Tags: <macro>
Title: Templating - Get a string of the entry's field handle
ThreadText: # Templating - Get a string of the entry's field handle
  
  (Asked by: username_0 on 2018-04-17)
  
  I'm passing entry fields into a macro and I'd like to be able to get a string of the field handle
  
  ```
  myMacro(entry.field1)
  myMacro(entry.field2)
  
  {% macro myMacro(entry) %}
    {# I want a string of 'field1' here #}
  {% endmacro %}
  
  ```
  
  **Tags:** macro
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-17. Score: 2
  
  You won't be able to do it that way because `entry.field2` will return you the normalized field value and there is no way to trace back some object|string|variable to an unknown entry with an unknown field handle. You need to pass the handle as a second parameter in your macro
  
  ```
  {% macro myMacro(field, fieldHandle) %}
      {{ fieldHandle }}
  {% endmacro %}
  
  myMacro(entry.field2, 'field2').
  
  ```
  
  You could also pass the entry and a field handle instead of the field
  
  ```
  {% macro myMacro(element, fieldHandle) %}
      {{ fieldHandle }}
      {% set value = element.getFieldValue(fieldHandle) %}
  {% endmacro %}
  
  myMacro(entry, 'field2').
  
  ```
  
  > **Comments:**
  > **username_0**: I had been passing the string in the macro, but was hoping to eliminate that as a requirment. I dig your second approach, I hadn't thought of that, but I'd be worried the loss of clarity may not be worth it in the long run. Cool all the same.  
  > **username_1**: Well... You have an object and you have an index, when you pass only the elements value you can't know what the corresponding index is. However - depending on the macro you should not lose that much insight just because you pass a handle  
  
  ---
  
  