Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-17T07:00:08.903Z
Answers.Text: Thanks for pointing to `BusinessLogic`. Pure gold!
Answers.UserDisplayName: Jannie Theunissen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T06:50:15.190Z
Answers.LastActivityDate: 2015-04-14T06:55:30.430Z
Answers.LastEditDate: 2015-04-14T06:55:30.430Z
Answers.UserDisplayName: Douglas McDonald
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-15T08:11:27.873Z
Answers.LastActivityDate: 2015-04-15T08:11:27.873Z
Answers.UserDisplayName: Richard G.
Body: <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>
  
Tags: <plugin-development><variable>
Title: Working with Variables
ThreadText: # 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:
  
  ```
  <?php
  namespace Craft;
  
  class HelloPlugin extends BasePlugin
  {
      function getName()
      {
           return Craft::t('Hello');
      }
  
      function getVersion()
      {
          return '1.0';
      }
  
      function getDeveloper()
      {
          return 'username_0 G.';
      }
  
      function getDeveloperUrl()
      {
          return 'http://example.com';
      }
  
          public function hasCpSection()
      {
          return true;
      }
  
  }
  
  plugins/hello/variables/HelloVariable
  
  <?php
  namespace Craft;
  
  class HelloVariable
  {
      // property
      $message = 'Hello, World";"
   }
  
  plugins/hello/templates/index.html
  
  {% extends "_layouts/cp" %}
  
  {% set title = "Hello World"|t %}
  
  {% set content %}
  
  <h2>MessageVariable  {{ craft.helloPlugin.HelloVariable.message }}</h2>
  
  {% 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](https://github.com/lindseydiloreto/craft-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 ...
  
  ```
  <?php
  namespace Craft;
  
  class HelloVariable
  {
      public function getMessage($msg)
      {
          return $msg;
      }
   }
  
  ```
  
  and for the template...
  
  ```
  {% extends "_layouts/cp" %}
  
  {% set title = "Hello World"|t %}
  
  {% set content %}
  
  <h2>{{ craft.hello.getMessage('Say something original...') }}</h2>
  
  {% endset %}
  
  ```
  
  which prints in the control panel...
  
  ```
   Hello World
  Say something original...
  
  ```
  
  
  ---
  
  