How to get Current Entry ID in Plugin Variable? I need to get the current entry ID in plugin's variable file without submitting any form. I tried this but it gave an error Undefined property: Craft\PluginNameVariable::$element

namespace Craft;

class PluginNameVariable
{
/**
 */
public function totalitemsForElements($elements = array())
{
    $criteria = craft()-&gt;elements-&gt;getCriteria('MyElementType');

    $criteria-&gt;elementId = $this-&gt;element-&gt;id;

    $items = $criteria-&gt;find();

    return $criteria-&gt;find();
}
}


I was accessing this variable through

{% set itemElementType =  craft.pluginName.totalitemsForElements %}
{{ itemElementType|length }}


Please Help. Thanks in advance !!
It seems like what you want is to get elements related to an entry that is pre-loaded in a template, and that elementId is a custom field for MyElementType. If that's the case, this should work out:

public function totalitemsForElements($elementID)
{
    $criteria = craft()-&gt;elements-&gt;getCriteria('MyElementType');

    $criteria-&gt;elementId = $elementID;

    return $criteria-&gt;find();
}


We'll pass the entry id to the variable function. Here's the template code:

{% set itemElementType =  craft.pluginName.totalitemsForElements(entry.id) %}
{{ itemElementType|length }}