<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>

CC BY-SA 3.0
2014-07-20T16:24:43.227Z
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.
Gareth
CC BY-SA 3.0
2014-08-15T13:30:25.500Z
That is useful, the super simple happy brad widget also helped a lot https://github.com/mattstauffer/happybrad
noregt
CC BY-SA 3.0
2014-07-20T13:18:02.497Z
2014-07-20T14:42:40.820Z
2014-07-20T14:42:40.820Z
Victor
<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>

<plugin-development><dashboard-widgets>
How to create a simple widget?
# 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:

**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 with your Dashboard Widget.
Plugin Structure:
Assuming your plugin is called username_0 and your widget Gr, this files should be in your /craft/plugins/gareth/ directory:

username_0Plugin.php
templates/

GrWidget.html

widgets/

username_0_GrWidget.php



Primary Plugin Class: username_0Plugin.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.



Widget Class: username_0_GrWidget.php
This class defines the widget types name getName() and its content getBodyHtml().
templates->render('gareth/GrWidget');
    }
}


Widget Template: GrWidget.html
This is just some text which will be shown inside the GrWidget.
A link to my user profile


Result:


More:
Check out the Widget documentation. 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  

---

