1

I am hoping that somebody can help with this issue.

I followed this excellent tutorial on creating a custom widget in Craft. On completion, I uploaded the plugin to the /craft/plugins/ directory, visited the page at /admin/settings/plugins and installed the plugin. All fine so far. Then, on returning to the dashboard, I clicked on New Widget, and selected the name of the widget. Following this, a message flashed up saying 'An unknown error occurred.' and little else happened.

It's probably user error, but if you could point out what I might have done incorrectly, that'd be useful.

My Plugin Structure

The plugin's called Adlister and the widget's called Alu, so in /craft/plugins/adlister/ I have two folders ( templates/ and widgets/ ), and a file: AdListerPlugin.php. Within templates/ is a file: AluWidget.html and within widgets/ is AdLister_AluWidget.php.

File Contents

AdListerPlugin.php

<?php
namespace Craft;

class AdListerPlugin extends BasePlugin
{
    function getName()
    {
         return Craft::t('AdLister');
    }

    function getVersion()
    {
        return '1.0';
    }

    function getDeveloper()
    {
        return 'Mark Syred';
    }

    function getDeveloperUrl()
    {
        return 'http://www.sypo.uk';
    }
}

AluWidget.html

<p>Click to perform <a href="http://example.co.uk/adlister-update.php?numDays=1">a daily update</a>.</p>
<p>Click to perform <a href="http://example.co.uk/adlister-update.php?numDays=3">an update on a Monday</a>.</p>
<p>Click to perform <a href="http://example.co.uk/adlister-update.php?numDays=7">a weekly update</a>.</p>
<p>Click to perform <a href="http://example.co.uk/adlister-update.php?numDays=30">a monthly update</a>.</p>

AdLister_AluWidget.php

<?php
namespace Craft;

class Adlister_AluWidget extends BaseWidget
{
    public function getName()
    {
        return Craft::t('Adlister Update');
    }

    public function getBodyHtml()
    {
        return craft()->templates->render('adlister/AluWidget');
    }
}

Any help that anyone could provide would be much appreciated.

With kind regards,

Mark

UPDATE

I don't know if this has any bearing, but the version of Craft I'm running is 2.6.2911.

7
  • I actually set up your plugin by using the code in your question, and adding the widget worked fine on my end. Are these stubs – i.e. anything else in your code besides the stuff you posted? Or is this the complete thing? Commented Aug 24, 2016 at 9:54
  • Also, did you check your log files under /craft/storage/runtime/logs (search for [error] and possibly your server error log files as well – might be a clue in there. Commented Aug 24, 2016 at 9:55
  • @MatsMikkelRummelhoff Thanks for your comment. The code in my question displays the complete code. It's good to know it works for someone! I will go ahead now and check the error logs... Commented Aug 24, 2016 at 10:05
  • Yeah, I set it up exactly like you describe, so without being able to reproduce the issue it's hard to advise. Hopefully there's a more helpful error message in the logs :) Commented Aug 24, 2016 at 10:06
  • @MatsMikkelRummelhoff I've checked the error logs - both on craft and in the server - and there's nothing relevant that I can see. I've resorted to contacting Pixel & Tonic via the Dashboard in Craft. Thanks anyway for your support. Commented Aug 24, 2016 at 10:30

1 Answer 1

2

I feel quite embarrassed, but I have finally got this thing working. The error that I had made was within AdLister_AluWidget.php. I had written at line 4: class Adlister_AluWidget extends BaseWidget instead of what it should have been: class AdLister_AluWidget extends BaseWidget. So, AdLister should have been written with an UPPER-CASE 'L' and not lower-case. If anyone else is struggling, hopefully my error will help them.

The correct code in full:

<?php
namespace Craft;

class AdLister_AluWidget extends BaseWidget
{
    public function getName()
    {
        return Craft::t('Adlister Update');
    }

    public function getBodyHtml()
    {
        return craft()->templates->render('adlister/AluWidget');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.