Answers.Body: <p>As far as I know. The variable {{ entry }} is not available to custom field plugins through inheritance and must be explicitly set and returned as a variable in the <code>getInputHtml</code> method within the class definition file. </p>
  
  <p>See <a href="https://craftcms.stackexchange.com/questions/4113/how-to-reference-the-current-entry-element-in-custom-control-panel-templates/4266?noredirect=1#comment4699_4266">this question</a> for details on how to set this variable and things to be aware of.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-21T21:49:14.063Z
Answers.LastActivityDate: 2014-10-21T21:49:14.063Z
Answers.LastEditDate: 2017-04-13T12:50:59.930Z
Answers.UserDisplayName: Douglas McDonald
Answers.Body: <p>A bit hard to tell what's going on without any code examples, but if you're just looking for a way to grab an entry from your plugin, and you already have the ID of the entry, then <a href="http://buildwithcraft.com/classreference/services/EntriesService" rel="nofollow">EntriesService</a> has a <a href="http://buildwithcraft.com/classreference/services/EntriesService#getEntryById-detail" rel="nofollow">getEntryById()</a> method available via <code>craft()-&gt;entries-&gt;getEntryById()</code> that your plugin can call.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-15T18:10:41.787Z
Answers.Text: Thank you, but not exactly what I'm looking for.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-15T18:27:09.210Z
Answers.Text: The plugin is designed to just evaluate a twig expression, and output the result into the field. Within the plugin settings you can define the twig expression to be evaluated. Something like {{ entry.unitPrice * entry.quantity }}. The problem is {{entry}} does not seem to work in this context. I'm looking for a way to reference the current entry within the admin panel. I don't know if there is already a variable defined for this, or if I should create a custom 'entry' or 'id' variable in the plugin, or if I should parse the uri within the twig expression to retrieve the id.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-12T16:02:21.263Z
Answers.LastActivityDate: 2014-09-12T16:02:21.263Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm trying to write a general use plugin for a calculation fieldtype that evaluates a twig expression (defined in the field settings) to display additional information about the current record in the CP (i.e. price * qty = amount). So far, everything is working perfectly — the generic expression <code>1 + 1</code> is evaluated and the result is properly displayed in the field.</p>
  
  <p>The problem is, I don't actually know how to reference the current entry in the CP from within the CP via twig, to get access to the entry field values. Looking for something like <code>{{ entry.price }} * {{ entry.qty }}</code>, but don't know what to use instead of <code>entry</code>. Does anyone know a twig expression that I can use?</p>
  
Tags: <plugin-development><control-panel>
Title: How to reference the current entry via twig in the control panel?
ThreadText: # How to reference the current entry via twig in the control panel?
  
  (Asked by: username_0 on 2014-09-12)
  
  I'm trying to write a general use plugin for a calculation fieldtype that evaluates a twig expression (defined in the field settings) to display additional information about the current record in the CP (i.e. price \* qty = amount). So far, everything is working perfectly — the generic expression `1 + 1` is evaluated and the result is properly displayed in the field.
  
  The problem is, I don't actually know how to reference the current entry in the CP from within the CP via twig, to get access to the entry field values. Looking for something like `{{ entry.price }} * {{ entry.qty }}`, but don't know what to use instead of `entry`. Does anyone know a twig expression that I can use?
  
  **Tags:** plugin-development, control-panel
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2014-10-21. Score: 2 | Accepted answer
  
  As far as I know. The variable {{ entry }} is not available to custom field plugins through inheritance and must be explicitly set and returned as a variable in the `getInputHtml` method within the class definition file.
  
  See [this question](https://craftcms.stackexchange.com/questions/4113/how-to-reference-the-current-entry-element-in-custom-control-panel-templates/4266?noredirect=1#comment4699_4266) for details on how to set this variable and things to be aware of.
  
  
  ---
  
  ### Answer by username_1 on 2014-09-12. Score: 1
  
  A bit hard to tell what's going on without any code examples, but if you're just looking for a way to grab an entry from your plugin, and you already have the ID of the entry, then [EntriesService](http://buildwithcraft.com/classreference/services/EntriesService) has a [getEntryById()](http://buildwithcraft.com/classreference/services/EntriesService#getEntryById-detail) method available via `craft()->entries->getEntryById()` that your plugin can call.
  
  > **Comments:**
  > **username_0**: Thank you, but not exactly what I'm looking for.  
  > **username_0**: The plugin is designed to just evaluate a twig expression, and output the result into the field. Within the plugin settings you can define the twig expression to be evaluated. Something like {{ entry.unitPrice * entry.quantity }}. The problem is {{entry}} does not seem to work in this context. I'm looking for a way to reference the current entry within the admin panel. I don't know if there is already a variable defined for this, or if I should create a custom 'entry' or 'id' variable in the plugin, or if I should parse the uri within the twig expression to retrieve the id.  
  
  ---
  
  