Widget not rendering


I’m starting to explore Yii2 using the basic template. I started to develop a widget which would render a result view, which would use Bootstrap in “raw” html, but nothing would be displayed on the page.

So I tried to copy the navbar code that comes with the template to my view file, and use the widget in the main layout, and still nothing showed up.

This is part of the main layout file:

<?= MyWidget::widget() ?>

This is the content of MyWidget class:

public function init()




public function run()




This is the view file:


use yii\bootstrap\Nav;

use yii\bootstrap\NavBar;


        'brandLabel' => 'My Company',

        'brandUrl' => Yii::$app->homeUrl,

        'options' => [

            'class' => 'navbar-inverse navbar-fixed-top',






MyWidget class is located at @app/components, and the associated view file is at @app/components/views.

Can someone see something wrong with this?

Any help would be appreciated :)

render() returns a string, so you have to echo the render result.

You are absolutely right.

Thank you very much, robRobson!