• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

Calling XenForo 2 Widgets From External Page

asphalt.jpg


XenForo 2 includes a means to call widgets from an external PHP page. The key is the templater() method.

PHP:
$templater = $app->templater();

/** @var \XF\Widget\WidgetRenderer $widgetRenderer */
$widgetRenderer = $templater->renderWidget('forum_overview_new_posts', []);
\XF::dump($widgetRenderer->render());

The links are still relative to the location of the PHP file but the result is fantastic. The CSS is absent, but that's an easier fix.

The [] may become optional in later releases.

Latest Post in XF2 Outside XF2.png


A template can also be called using the templater():

PHP:
$templater = $app->templater();

$viewParams = [];
$output = $templater->renderTemplate('public:account_visitor_menu');
\XF::dump($output);
  • Like
Reactions: robru

Blog entry information

Author
LPH
Views
2,393
Last update

More entries in General

More entries from LPH

Top