<p>There are multiple issues happening here...</p>

<ol>
<li><p>The Twig code should look like this:</p>

<pre><code>{{ craft.businessLogic.exampleVariable() }}
</code></pre></li>
<li><p>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.</p></li>
</ol>

<p>Optional...</p>

<ol start="3">
<li>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.</li>
</ol>

CC BY-SA 4.0
2018-08-16T17:28:15.663Z
2018-08-16T17:28:15.663Z
Lindsey D
<p>I'm just starting with plugins and I've downloaded the Business Logic plugin and am trying to call it from my template.  </p>

<p>Here's the code in my template:</p>

<pre><code>{% extends "_layout" %}

{% block content %}
{{craft()-&gt;businessLogic-&gt;exampleService()}}

{% endblock %}
</code></pre>

<p>And the code in the BusinessLogicService.php:</p>

<pre><code>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()-&gt;businessLogic-&gt;exampleService()
     *
     */
    public function exampleService()
    {
        return "I've got your data right here!";
    }

}
</code></pre>

<p>It returns this error:</p>

<pre><code>Unknown "craft" function.
</code></pre>

<p>Would I call it a different way?<br>
Thanks for any help with this.</p>

CC BY-SA 4.0
2018-08-16T17:21:37.697Z
Is this a Craft 2 site or a Craft 3 site?
Lindsey D
CC BY-SA 4.0
2018-08-16T20:28:24.550Z
It's a Craft 2 site.
buck1112
CC BY-SA 4.0
2018-08-16T21:16:11.820Z
You can also generated your plugin scaffolding here: https://pluginfactory.io/ -- so you'll get just what you want.
andrew.welch
<plugins><services>
"Unknown "craft" function" Error in Plugin Service Call
# "Unknown "craft" function" Error in Plugin Service Call

(Asked by: username_0 on 2018-08-16)

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 %}
{{craft()->businessLogic->exampleService()}}

{% 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.

**Tags:** plugins, services
> **Comments:**
> **username_1**: Is this a Craft 2 site or a Craft 3 site?  
> **username_0**: It's a Craft 2 site.  
> **username_2**: You can also generated your plugin scaffolding here: https://pluginfactory.io/ -- so you'll get just what you want.  

---

## 1 answers

### Answer by username_1 on 2018-08-16. Score: 1

There are multiple issues happening here...

The Twig code should look like this:
{{ craft.businessLogic.exampleVariable() }}

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.

Optional...

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.


---

