<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>

CC BY-SA 3.0
2014-10-21T21:49:14.063Z
2014-10-21T21:49:14.063Z
2017-04-13T12:50:59.930Z
Douglas McDonald
<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>

CC BY-SA 3.0
2014-09-15T18:10:41.787Z
Thank you, but not exactly what I'm looking for.
Douglas McDonald
CC BY-SA 3.0
2014-09-15T18:27:09.210Z
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.
Douglas McDonald
CC BY-SA 3.0
2014-09-12T16:02:21.263Z
2014-09-12T16:02:21.263Z
Brad Bell
<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>

<plugin-development><control-panel>
How to reference the current entry via twig in the control panel?
# 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.  

---

