XF 2.0 Wow do you create html widgets in setup.php?

Earl

Well-known member
If you are familiar with the widget system in XenForo, as you may be aware, this special kind 'HTML' type widget, allows you to add raw HTML code to your site.

I can create other type widgets when installing the addon, in setup.php

but How do you create this HTML type widget using installSteps in setup.php file?

PHP:
public function installStep1()

{

    $this->createWidget('earl_my_addon_widget', 'html', [

        'positions' => ['earl_wpos_bottom_navbar' => 10],

        'options' => ['advanced_mode' => true,

            'template_title' => 'my widget title',

           ]

    ]);

}
This code will be enough to create the addon, but it gives an error when page loading because I didn't set a template.
How do you create the template and bind to it?
 
okay I got this, I just have to create a new template manually using entity manager, and prefix it _widget_ followed by widget ID
 
I know this is a thread from 2018, but if the author of this thread is still active.. Can you explain how you did it, because I try to do the same but it won't work.
 
@Gh0stAdventures

First go to ACP then to Widget definitions menu and add information of widget the important things is

Definition ID > which will use it in setup file
Definition Class > is the name of widget php file.

So if Definition id is TestWidget and Definition Class will be Demo\XF\Widget\TestWidget.php

And in the setup file you have to define widget like below :

PHP:
public function installStep1()
{

    $this->createWidget(
        'TestWidget',
        'TestWidget',
        [
            'positions' => ['forum_list_sidebar' => 10],
        ]);

}

Then you have to create new template with prefix widget_test_widget and you can see any core widget template and follow the same

I hope this help
 
@Gh0stAdventures

First go to ACP then to Widget definitions menu and add information of widget the important things is

Definition ID > which will use it in setup file
Definition Class > is the name of widget php file.

So if Definition id is TestWidget and Definition Class will be Demo\XF\Widget\TestWidget.php

And in the setup file you have to define widget like below :

PHP:
public function installStep1()
{

    $this->createWidget(
        'TestWidget',
        'TestWidget',
        [
            'positions' => ['forum_list_sidebar' => 10],
        ]);

}

Then you have to create new template with prefix widget_test_widget and you can see any core widget template and follow the same

I hope this help
Thanks a lot ! This will def help me out, now I understand how the process is build up in order to create the widget. Thanks !!
 
Top Bottom