Jump to content
  • Status: Moved to Github

Hello,

My Widget contains the following:

public function init() : void

{
parent::init();

// Use this to perform any set up and to assign a template that is not in the following format:
// $this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' ), $this->key ) );
// Note: parent::init() will set a default template, so make sure your template is defined after the parent is called.

// use the the cms pagebuilderupload template (ensure this is done AFTER call to parent)
$this->template([\IPS\Theme::i()->getTemplate('widgets', 'cms', 'front'), 'pagebuilderupload']);
}

But when I install the application/widget on our live system it results in the following ErrorException:

Error: ErrorException: template_store_missing in /home/bn1379/public_html/system/Theme/Theme.php:927
Stack trace:
#0 /home/bn1379/public_html/system/Widget/Widget.php(234): IPS\Theme->getTemplate('widgets', 'bnimg', 'front')
#1 /home/bn1379/public_html/applications/bnimg/widgets/carouselFromDB.php(52): IPS\Widget->init()
#2 /home/bn1379/public_html/system/Widget/Widget.php(214): IPS\bnimg\widgets\carouselFromDB->init()
#3 /home/bn1379/public_html/system/Widget/Widget.php(759): IPS\Widget->__construct('exlqb60iw', Array, NULL, 'horizontal', 'wrap')
#4 /home/bn1379/public_html/system/Widget/Widget.php(1744): IPS\Widget::load(Object(IPS\bnimg\Application), 'carouselFromDB', 'exlqb60iw', Array, NULL, 'horizontal', 'wrap')
#5 /home/bn1379/public_html/system/Widget/Area.php(981): IPS\Widget::createWidgetFromStoredData(Array)
#6 /home/bn1379/public_html/system/Widget/Area.php(950): IPS\Widget\Area->getWidgetContent()
#7 /home/bn1379/public_html/system/Widget/Area.php(958): IPS\Widget\Area->totalVisibleWidgets()
#8 /home/bn1379/public_html/static/templates/core_front_global.php(23872): IPS\Widget\Area->totalVisibleWidgets()
#9 /home/bn1379/public_html/system/Theme/SandboxedTemplate.php(68): IPS\Theme\class_core_front_global->widgetArea(Object(IPS\Widget\Area))
#10 /home/bn1379/public_html/system/Widget/Area.php(288): IPS\Theme\SandboxedTemplate->__call('widgetArea', Array)
#11 /home/bn1379/public_html/applications/cms/sources/Pages/Page.php(2230): IPS\Widget\Area->__toString()
#12 /home/bn1379/public_html/applications/cms/sources/Pages/Page.php(2124): IPS\cms\Pages\Page->getPageContent()
#13 /home/bn1379/public_html/applications/cms/modules/front/pages/page.php(122): IPS\cms\Pages\Page->output()
#14 /home/bn1379/public_html/applications/cms/modules/front/pages/page.php(49): IPS\cms\modules\front\pages\page->view()
#15 /home/bn1379/public_html/system/Dispatcher/Controller.php(139): IPS\cms\modules\front\pages\page->manage()
#16 /home/bn1379/public_html/system/Dispatcher/Dispatcher.php(169): IPS\Dispatcher\Controller->execute()
#17 /home/bn1379/public_html/index.php(16): IPS\Dispatcher->run()
#18 {main} in /home/bn1379/public_html/system/Theme/SandboxedTemplate.php:72

Stack trace:
#0 /home/bn1379/public_html/system/Widget/Area.php(288): IPS\Theme\SandboxedTemplate->__call('widgetArea', Array)
#1 /home/bn1379/public_html/applications/cms/sources/Pages/Page.php(2230): IPS\Widget\Area->__toString()
#2 /home/bn1379/public_html/applications/cms/sources/Pages/Page.php(2124): IPS\cms\Pages\Page->getPageContent()
#3 /home/bn1379/public_html/applications/cms/modules/front/pages/page.php(122): IPS\cms\Pages\Page->output()
#4 /home/bn1379/public_html/applications/cms/modules/front/pages/page.php(49): IPS\cms\modules\front\pages\page->view()
#5 /home/bn1379/public_html/system/Dispatcher/Controller.php(139): IPS\cms\modules\front\pages\page->manage()
#6 /home/bn1379/public_html/system/Dispatcher/Dispatcher.php(169): IPS\Dispatcher\Controller->execute()
#7 /home/bn1379/public_html/index.php(16): IPS\Dispatcher->run()
#8 {main}

Incidentally, on our test/development system it does not fail. I believe this is because I had been trying various things on the test system and had created the default template at some stage - so it existed on the test system (although it was not being used) but as it did not exist on the live/production system the exception occurred on the live system.

I previously logged a related bug - it must have been under Beta as I cannot find it now. I had suggested that the comments in the Widget template were wrong because if you call $this->template() before calling parent::init() then parent::init() just overrides your own template. Unfortunately, my earlier bug report was not the complete story!

I suggest that the correct sequence would be to call $this->template() to set up your own template BEFORE calling parent::init() and then parent::init() should test whether the template has already been set up and if it has, then do not override it.

That sequence would ensure that a template has been set up while at the same time avoid overriding any template that you have set up.

Thanks very much.

John

User Feedback

Recommended Comments

Esther E.

Invision Community Team

The issue here is that you're calling the parent method, which will attempt to load the default.

Just remove the call to parent::init and you'll be good to go.

BN_IT_Support

Clients

Esther,

Yes - I forgot to say - that was already my workaround.

As things stand at present, the only thing that parent::init() does is the call to define the default template. But what if you (Invision) decide to do additional things at some point in the future? It would be very good if I (and other developers) could just keep the parent::init() in our code so that our Widgets are largely future-proofed against things that you might add in the future.

Thanks.

John