Plugin service and variable I have a service called useTR.php. It has a public method exampleService(). 

In the variables folder I have added the following code in my KGVariable.php (KG is my plugin name)

public function sayHello() {
    return craft()-&gt;useTR-&gt;exampleService();
}


In my templates folder I have an html that gets loaded after a form submission and that html has the following code. 

&lt;p&gt;Thank you {{ craft.KG.sayHello() }} will contact you soon&lt;/p&gt;


When this HTML is loaded, I get the following error:


  Twig Runtime Error – Twig_Error_Runtime
  Calling unknown method: craft\web\twig\variables\CraftVariable::keyword()


What am I doing wrong? Kindly help (I am a beginner at Craft). Thanks.
There's a lot going on here, but a) assuming you're really using Craft 3 and b) you generated your plugin, service and variable scaffolding on https://pluginfactory.io, this should work:

KGVariable.php Variable

&lt;?php

namespace kg\variables;

class KGVariable
{
    public function sayHello()
    {
        return \kg\KG::$plugin-&gt;useTR-&gt;exampleService();
    }
}


UseTR.php Service

&lt;?php

namespace kg\services;

use craft\base\Component;

class UseTR extends Component
{
    public function exampleService()
    {
        $result = 'hello';
        return $result;
    }
}


Then using this in a template will return hello:

{{ craft.kG.sayHello() }}