<p>Within your variables class file you will want to define methods that 'return' values to your template, like so:</p>

<pre><code>class HelloVariable
{
    public function message()
    {
        return "Hello, world!";
    }
}
</code></pre>

<p>Which you would call from your template using:</p>

<pre><code>{{ craft.hello.message }}
</code></pre>

<p>On a side note, a really good place to start plugin development is to download and install a plugin template such as <a href="https://github.com/lindseydiloreto/craft-businesslogic">BusinessLogic</a>, which provides a basic plugin structure, some sample files, and includes inline documentation for basic business logic kind of functionality.</p>

CC BY-SA 4.0
2020-01-17T07:00:08.903Z
Thanks for pointing to `BusinessLogic`. Pure gold!
Jannie Theunissen
CC BY-SA 3.0
2015-04-14T06:50:15.190Z
2015-04-14T06:55:30.430Z
2015-04-14T06:55:30.430Z
Douglas McDonald
<p>Here is my corrected code ...</p>

<pre><code>&lt;?php
namespace Craft;

class HelloVariable
{
    public function getMessage($msg)
    {
        return $msg;
    }
 }
</code></pre>

<p>and for the template...</p>

<pre><code>{% extends "_layouts/cp" %}

{% set title = "Hello World"|t %}

{% set content %}

&lt;h2&gt;{{ craft.hello.getMessage('Say something original...') }}&lt;/h2&gt;

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

<p>which prints in the control panel...</p>

<pre><code> Hello World
Say something original...
</code></pre>

CC BY-SA 3.0
2015-04-15T08:11:27.873Z
2015-04-15T08:11:27.873Z
Richard G.
<p>How do I display a variable in my template?</p>

<p>I have the following code:</p>

<pre><code>&lt;?php
namespace Craft;

class HelloPlugin extends BasePlugin
{
    function getName()
    {
         return Craft::t('Hello');
    }

    function getVersion()
    {
        return '1.0';
    }

    function getDeveloper()
    {
        return 'Richard G.';
    }

    function getDeveloperUrl()
    {
        return 'http://example.com';
    }

        public function hasCpSection()
    {
        return true;
    }

}

plugins/hello/variables/HelloVariable

&lt;?php
namespace Craft;

class HelloVariable
{
    // property
    $message = 'Hello, World";"
 }


plugins/hello/templates/index.html

{% extends "_layouts/cp" %}

{% set title = "Hello World"|t %}

{% set content %}

&lt;h2&gt;MessageVariable  {{ craft.helloPlugin.HelloVariable.message }}&lt;/h2&gt;

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

<plugin-development><variable>
Working with Variables
# Working with Variables

(Asked by: username_0 on 2015-04-14)

How do I display a variable in my template?
I have the following code:
MessageVariable  {{ craft.helloPlugin.HelloVariable.message }}

{% endset %}

**Tags:** plugin-development, variable


---

## 2 answers

### Answer by username_1 on 2015-04-14. Score: 6

Within your variables class file you will want to define methods that 'return' values to your template, like so:
class HelloVariable
{
    public function message()
    {
        return "Hello, world!";
    }
}

Which you would call from your template using:
{{ craft.hello.message }}

On a side note, a really good place to start plugin development is to download and install a plugin template such as BusinessLogic, which provides a basic plugin structure, some sample files, and includes inline documentation for basic business logic kind of functionality.

> **Comments:**
> **username_2**: Thanks for pointing to `BusinessLogic`. Pure gold!  

---

### Answer by username_0 on 2015-04-15. Score: 1

Here is my corrected code ...

and for the template...
{% extends "_layouts/cp" %}

{% set title = "Hello World"|t %}

{% set content %}

{{ craft.hello.getMessage('Say something original...') }}

{% endset %}

which prints in the control panel...
 Hello World
Say something original...


---

