Creating New Widgets

in Hubzilla

By Scott M. Stolz, et al.

Class Based Widget

To create a class-based widget named slugfish create a file with the following contents:

  <?php

namespace Zotlabs\Widget;

class Slugfish {

function widget($args) {

... widget code goes here.
... The function returns a string which is the HTML content of the widget.
... $args is a named array which is passed any [var] variables from the layout editor
... For instance [widget=slugfish][var=count]3[/var][/widget] will populate $args with
... [ 'count' => 3 ]

}
}

The resultant file may be placed in widget/Slugfish/Slugfish.php or Zotlabs/SiteWidgets/Slugfish.php. It also may be linked from a git repository using util/add_widget_repo.

Traditional Function Based Widget

If you want a widget named slugfish, create widget/widget_slugfish.php containing:

<?php    
function widget_slugfish($args) {    
.. widget code goes here. See above information for class-based widgets for details.    
}

Content for tab 2.

Content for tab 3.

Creating New Widgets

in Hubzilla
Permalink

This Article:   Last Minor Update: 2022-10-12   Last Major Update: 2022-10-12  

Sorry, you have got no notifications at the moment...
Aside
Sorry, you have got no notifications at the moment...
User Menu