How to reference the current entry element in custom Control Panel templates? This might provide it's own answer, but I thought I would ask to be sure. How do you reference the current entry in custom fieldType or CP templates? I have tried {{ entry.id }}, {{ element.id }} but neither work. Do you need to explicitly set these variables in your getInputHTML() function?

I see in the craft '_entry.html' template that {{ entry.id }} is used for a hidden field. Since that reference is not available, I assume that template variables are scoped to the template and not inherited by other templates on the same page?

Through trial and error I finally discovered the current entry can be referenced in PHP as $this-&gt;element;, and the id and section via $this-&gt;element-&gt;id, $this-&gt;element-&gt;section respectively. So, I could add entry as a template variable, but I just assumed it would already be there.

public function getInputHtml($name, $value)
{
    $entry = $this-&gt;element;
    return craft()-&gt;templates-&gt;render('myPlugin/fieldtypes/MyField/input', array(
        'name'          =&gt; $name,
        'value'         =&gt; $value,
        'entry'         =&gt; $entry
    );
}
As you discovered, you can get the current element that a field type is getting applied to via $this-&gt;element. However you must keep in mind that that property will not always be set. So make sure that your PHP/template code is defensive about the possibility that there is no known element yet.

Another assumption to avoid is that the current element is going to be an entry. Craft lets you associate fields with any type of element - entries, users, assets, categories, tags, globals, and Matrix blocks, and even any custom element types that plugins may add. So $this-&gt;element-&gt;section should be avoided unless you know that $this-&gt;element is actually an EntryModel; otherwise that will give you a PHP error.