XF 2.0 renderWidget outside XF

LPH

Well-known member
It's possible to render a widget outside XF. For example:

PHP:
$widget = \XF::app()->templater()->renderWidget('forum_overview_members_online');
echo $widget;

Unfortunately, the links are relative to the boardUrl and the avatar doesn't show the gravatar.

XF2 Sidebar in WordPress.webp

In looking at renderWidget, there are options and arguments but I can't trace down anything that would change the URL from relative to canonical. Is this possible?
 
I'm not sure if extending AbstractWidget will work and got stuck on how to instantiate the class. Does anyone have any suggestions?

PHP:
use XF\Widget\AbstractWidget;

class MembersOnline extends AbstractWidget {

   public function render() {
      $link = \XF::app()->router( 'public' )->buildLink( 'canonical:members' );

      $viewParams = [ 'link' => $link, ];

      return $this->renderer( 'widget_members_online', $viewParams );
   }
}
 
Go to /admin.php?widgets/definitions/add and add your custom widget there.
Then add your widget with no position /admin.php?widgets/add (remember the id).
Finally, use your code from post #1 with the custom widget id from step 2.
 
Go to /admin.php?widgets/definitions/add and add your custom widget there.
Then add your widget with no position /admin.php?widgets/add (remember the id).
Finally, use your code from post #1 with the custom widget id from step 2.

how do I set the forum path?
 
Back
Top Bottom