Return the contents of a template from a custom Twig function in a module? I have a template that outputs some JSON formatted data.

I've built a simple module that needs to get the contents of that template, decode the JSON data, and return it.

I believe I need to use craft()-&gt;templates-&gt;render('path/to/template'), but when I do, I get:

Call to undefined function modules\importjsonmodule\twigextensions\craft()

The only explanation I can think of is that craft() cannot be used in a module in the way it can in a plugin. Is that the case? If so, is there any way I can access the Templates service from within a module?

Thanks
There is no craft() function in Craft 3 and there are no Modules in Craft 2.
You probably mix the two different versions.
Craft 3
Craft::$app-&gt;getView()-&gt;renderTemplate('/path/to/template');

Of course you need to be in the correct namespace. You have to either use Craft or do \Craft
Craft 2
craft()-&gt;templates-&gt;render('path/to/template')