I'm just starting with plugins and I've downloaded the Business Logic plugin and am trying to call it from my template.

Here's the code in my template:

{% extends "_layout" %}

{% block content %}

{% endblock %}

And the code in the BusinessLogicService.php:

class BusinessLogicService extends BaseApplicationComponent


     * This function can literally be anything you want.
     * HOW TO USE IT
     * From any other plugin file, call it like this:
     *     craft()->businessLogic->exampleService()
    public function exampleService()
        return "I've got your data right here!";


It returns this error:

Unknown "craft" function.

Would I call it a different way?
Thanks for any help with this.

  • 1
    Is this a Craft 2 site or a Craft 3 site?
    – Lindsey D
    Aug 16 '18 at 17:21
  • It's a Craft 2 site.
    – buck1112
    Aug 16 '18 at 20:28
  • 1
    You can also generated your plugin scaffolding here: pluginfactory.io -- so you'll get just what you want. Aug 16 '18 at 21:16

There are multiple issues happening here...

  1. The Twig code should look like this:

    {{ craft.businessLogic.exampleVariable() }}
  2. As noted in that example, Twig can't communicate directly with a Service level method. You'll need to ping the Variable class, and use your Variable method to call the Service method.


  1. The Business Logic plugin template currently only works with Craft 2. If you're attempting this on a Craft 3 site, several things would need to be changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.