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->element;
, and the id and section via $this->element->id
, $this->element->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->element;
return craft()->templates->render('myPlugin/fieldtypes/MyField/input', array(
'name' => $name,
'value' => $value,
'entry' => $entry
);
}