Skip to content

Commit 5a54cb3

Browse files
author
Christoph Erdmann
committed
optimization NavBar
1 parent f5a325e commit 5a54cb3

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/widgets/NavBar.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,50 +80,55 @@ public function init()
8080
{
8181
parent::init();
8282
$this->clientOptions = false;
83+
$html = [];
8384

8485
if (empty($this->options['role'])) {
8586
$this->options['role'] = 'navigation';
8687
}
8788

8889
if ($this->fixed) {
8990
Html::addCssClass($this->fixedContainerOptions, 'navbar-fixed');
90-
echo Html::beginTag('div', $this->fixedContainerOptions);
91+
$html[] = Html::beginTag('div', $this->fixedContainerOptions);
9192
}
9293

93-
$options = $this->options;
94-
echo Html::beginTag('nav', $this->options);
94+
$html[] = Html::beginTag('nav', $this->options);
9595

9696
Html::addCssClass($this->wrapperOptions, 'nav-wrapper');
97-
echo Html::beginTag('div', $this->wrapperOptions);
97+
$html[] = Html::beginTag('div', $this->wrapperOptions);
9898

9999
if ($this->brandLabel !== false) {
100100
Html::addCssClass($this->brandOptions, ['widget' => 'brand-logo']);
101-
echo Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions);
101+
$html[] = Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions);
102102
}
103103

104104
if (!isset($this->containerOptions['id'])) {
105105
$this->containerOptions['id'] = "{$this->id}-collapse";
106106
}
107-
echo $this->renderToggleButton();
108-
echo Html::beginTag('div', $this->containerOptions);
107+
$html[] = $this->renderToggleButton();
108+
$html[] = Html::beginTag('div', $this->containerOptions);
109+
110+
echo implode("\n", $html);
109111
}
110112

111113
/**
112114
* Renders the widget.
113115
*/
114116
public function run()
115117
{
116-
echo Html::endTag('div'); // container
118+
$html = [];
119+
$html[] = Html::endTag('div'); // container
117120

118-
echo Html::endTag('div'); // nav-wrapper
121+
$html[] = Html::endTag('div'); // nav-wrapper
119122

120-
echo Html::endTag('nav');
123+
$html[] = Html::endTag('nav');
121124

122125
if ($this->fixed) {
123-
echo Html::endTag('div');
126+
$html[] = Html::endTag('div');
124127
}
125128

126129
MaterializePluginAsset::register($this->getView());
130+
131+
return implode("\n", $html);
127132
}
128133

129134
/**

0 commit comments

Comments
 (0)