Answers.Body: <p>I think you are mixing up your <a href="http://buildwithcraft.com/docs/plugins/setting-things-up" rel="noreferrer">Primary Plugin Class</a> with your <a href="http://buildwithcraft.com/docs/plugins/widgets" rel="noreferrer">Dashboard Widget</a>.</p>
  
  <p><strong>Plugin Structure:</strong></p>
  
  <p>Assuming your plugin is called <code>Gareth</code> and your widget <code>Gr</code>, this files should be in your <code>/craft/plugins/gareth/</code> directory:</p>
  
  <ul>
  <li><code>GarethPlugin.php</code></li>
  <li><code>templates/</code>
  
  <ul>
  <li><code>GrWidget.html</code></li>
  </ul></li>
  <li><code>widgets/</code>
  
  <ul>
  <li><code>Gareth_GrWidget.php</code></li>
  </ul></li>
  </ul>
  
  <hr>
  
  <p><strong><a href="http://buildwithcraft.com/docs/plugins/setting-things-up" rel="noreferrer">Primary Plugin Class</a>: <code>GarethPlugin.php</code></strong></p>
  
  <blockquote>
    <p>Your primary plugin class defines all of the things that Craft needs
    to know about your plugin, such as the plugin’s name, version number,
    developer’s name and URL, and Global Settings.</p>
  </blockquote>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  namespace Craft;
  
  class GarethPlugin extends BasePlugin
  {
      function getName()
      {
           return Craft::t('Gareth');
      }
  
      function getVersion()
      {
          return '1.0';
      }
  
      function getDeveloper()
      {
          return 'Gareth Redfern';
      }
  
      function getDeveloperUrl()
      {
          return 'http://garethredfern.com';
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong><a href="http://buildwithcraft.com/docs/plugins/widgets" rel="noreferrer">Widget Class</a>: <code>Gareth_GrWidget.php</code></strong></p>
  
  <p>This class defines the widget types name <code>getName()</code> and its content <code>getBodyHtml()</code>.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  namespace Craft;
  
  class Gareth_GrWidget extends BaseWidget
  {
      public function getName()
      {
          return Craft::t('Gr');
      }
  
      public function getBodyHtml()
      {
          return craft()-&gt;templates-&gt;render('gareth/GrWidget');
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong><a href="http://buildwithcraft.com/docs/plugins/templates" rel="noreferrer">Widget Template</a>: <code>GrWidget.html</code></strong></p>
  
  <pre class="lang-twig prettyprint-override"><code>This is just some text which will be shown inside the GrWidget.
  &lt;a href="{{ url('myaccount') }}"&gt;A link to my user profile&lt;/a&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Result:</strong></p>
  
  <p><img src="https://i.sstatic.net/4uuzT.jpg" alt="How the example Widget will look like"></p>
  
  <hr>
  
  <p><strong>More:</strong></p>
  
  <p>Check out the <a href="http://buildwithcraft.com/docs/plugins/widgets" rel="noreferrer">Widget documentation</a>. Also take a look at Craft's default widgets which can be found in the <code>craft/app/widgets</code> directory.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-20T16:24:43.227Z
Answers.Text: Perfect, thank you Victor. You are right I wasn't really sure where to start but you have put me on the right path now. I hadn't seen the widget docs either so my bad there.
Answers.UserDisplayName: Gareth
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T13:30:25.500Z
Answers.Text: That is useful, the super simple happy brad widget also helped a lot https://github.com/mattstauffer/happybrad
Answers.UserDisplayName: noregt
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-20T13:18:02.497Z
Answers.LastActivityDate: 2014-07-20T14:42:40.820Z
Answers.LastEditDate: 2014-07-20T14:42:40.820Z
Answers.UserDisplayName: Victor
Body: <p>I have limited knowledge of PHP but I would like to try and create a widget. Basically all it needs to do is provide some text and a link to the user profile page as you can't route directly to that page on login. Would someone be able to point me in the write direction please. I have in my <code>grWidget.php</code> file:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace Craft;
  
  class GrWidget extends BasePlugin
  {
    function getName()
      {
        return Craft::t('Gareth Widget');
      }
  
      function getVersion()
      {
        return '1.0';
      }
  
      function getDeveloper()
      {
        return 'Gareth Redfern';
      }
  
      function getDeveloperUrl()
      {
        return 'http://garethredfern.com';
      }
  }
  </code></pre>
  
Tags: <plugin-development><dashboard-widgets>
Title: How to create a simple widget?
ThreadText: # How to create a simple widget?
  
  (Asked by: username_0 on 2014-07-20)
  
  I have limited knowledge of PHP but I would like to try and create a widget. Basically all it needs to do is provide some text and a link to the user profile page as you can't route directly to that page on login. Would someone be able to point me in the write direction please. I have in my `grWidget.php` file:
  
  ```php
  <?php
  
  namespace Craft;
  
  class GrWidget extends BasePlugin
  {
    function getName()
      {
        return Craft::t('username_0 Widget');
      }
  
      function getVersion()
      {
        return '1.0';
      }
  
      function getDeveloper()
      {
        return 'username_0 Redfern';
      }
  
      function getDeveloperUrl()
      {
        return 'http://garethredfern.com';
      }
  }
  
  ```
  
  **Tags:** plugin-development, dashboard-widgets
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-20. Score: 8 | Accepted answer
  
  I think you are mixing up your [Primary Plugin Class](http://buildwithcraft.com/docs/plugins/setting-things-up) with your [Dashboard Widget](http://buildwithcraft.com/docs/plugins/widgets).
  
  **Plugin Structure:**
  
  Assuming your plugin is called `username_0` and your widget `Gr`, this files should be in your `/craft/plugins/username_0/` directory:
  
  * `GarethPlugin.php`
  * `templates/`
    + `GrWidget.html`
  * `widgets/`
    + `Gareth_GrWidget.php`
  
  ---
  
  **[Primary Plugin Class](http://buildwithcraft.com/docs/plugins/setting-things-up): `GarethPlugin.php`**
  
  > Your primary plugin class defines all of the things that Craft needs
  > to know about your plugin, such as the plugin’s name, version number,
  > developer’s name and URL, and Global Settings.
  
  ```php
  <?php
  namespace Craft;
  
  class GarethPlugin extends BasePlugin
  {
      function getName()
      {
           return Craft::t('username_0');
      }
  
      function getVersion()
      {
          return '1.0';
      }
  
      function getDeveloper()
      {
          return 'username_0 Redfern';
      }
  
      function getDeveloperUrl()
      {
          return 'http://garethredfern.com';
      }
  }
  
  ```
  
  ---
  
  **[Widget Class](http://buildwithcraft.com/docs/plugins/widgets): `Gareth_GrWidget.php`**
  
  This class defines the widget types name `getName()` and its content `getBodyHtml()`.
  
  ```php
  <?php
  namespace Craft;
  
  class Gareth_GrWidget extends BaseWidget
  {
      public function getName()
      {
          return Craft::t('Gr');
      }
  
      public function getBodyHtml()
      {
          return craft()->templates->render('username_0/GrWidget');
      }
  }
  
  ```
  
  ---
  
  **[Widget Template](http://buildwithcraft.com/docs/plugins/templates): `GrWidget.html`**
  
  ```twig
  This is just some text which will be shown inside the GrWidget.
  <a href="{{ url('myaccount') }}">A link to my user profile</a>
  
  ```
  
  ---
  
  **Result:**
  
  ![How the example Widget will look like](https://i.sstatic.net/4uuzT.jpg)
  
  ---
  
  **More:**
  
  Check out the [Widget documentation](http://buildwithcraft.com/docs/plugins/widgets). Also take a look at Craft's default widgets which can be found in the `craft/app/widgets` directory.
  
  > **Comments:**
  > **username_0**: Perfect, thank you username_1. You are right I wasn't really sure where to start but you have put me on the right path now. I hadn't seen the widget docs either so my bad there.  
  > **username_2**: That is useful, the super simple happy brad widget also helped a lot https://github.com/mattstauffer/happybrad  
  
  ---
  
  