Call function from plugin in template
You'll need to register your variable in your plugin's init() method, like this:

Event::on(
    CraftVariable::class,
    CraftVariable::EVENT_INIT,
    function (Event $event) {
        /** @var CraftVariable $variable */
        $variable = $event-&gt;sender;
        $variable-&gt;set('pluginname', PluginVariable::class);
    }
);


c.f.: https://docs.craftcms.com/v3/extend/extending-twig.html