DarkSlash
(Darkslash)
July 10, 2015, 4:38pm
1
Im playing with the default Yii theme. I replace the brandlabel from text to image using:
'brandLabel' => Html::img('@web/images/logo.png',['id' => 'logo'])
and it worked perfectly. Now I want to put a lock icon next to the Logout word, so I used the html helper again:
$menuItems[] = [
'label' => Html::tag('span','',['class' => 'glyphicon glyphicon-lock']).' Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];
This time, instead of showing the tag, shows the tag as text (at some point its escaped so I see the text <span class="glyphicon glyphicon-lock"></span> instead of the lock icon).
How it needs to be done in this case?
gugoan
(Gugoan)
July 11, 2015, 2:12pm
2
Try using encodeLabels as false
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'encodeLabels' => false,
'items' => $menuItems
1 Like
DarkSlash
(Darkslash)
July 12, 2015, 2:08pm
3
The example is using NavBar::begin and NavBar::end instead of Nav::widget. Is a way to use it in that way? the property encodeLabels is not present in NavBar class.
johnitvn
(John Itvn)
July 14, 2015, 8:24am
4
I have try to run with your config. It 's worked fine. I don’t understand your problem
NavBar::begin(['brandLabel' => Html::img('@web/images/logo.png',['id' => 'logo'])]);
echo Nav::widget([
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
],
]);
NavBar::end();
skapeyi
(Kapeyisamson)
July 15, 2015, 4:13am
5
DarkSlash:
Im playing with the default Yii theme. I replace the brandlabel from text to image using:
'brandLabel' => Html::img('@web/images/logo.png',['id' => 'logo'])
and it worked perfectly. Now I want to put a lock icon next to the Logout word, so I used the html helper again:
$menuItems[] = [
'label' => Html::tag('span','',['class' => 'glyphicon glyphicon-lock']).' Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];
This time, instead of showing the tag, shows the tag as text (at some point its escaped so I see the text <span class="glyphicon glyphicon-lock"></span> instead of the lock icon).
How it needs to be done in this case?
Try this
<?php
NavBar::begin([
'brandLabel' => 'myRide',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Icon::show('home').'Home', 'url' => ['/site/index']];
$menuItems[] = ['label'=> Icon::show('account').'Account', 'items' => [
['label' => Icon::show('pencil').'Signup', 'url' => ['/site/signup']],
['label' => Icon::show('sign-in').'Login', 'url' => ['/site/login']],
]];
} else {
$menuItems[] = ['label' => Icon::show('home').'Home', 'url' => ['/site/index']];
$menuItems[] = ['label'=> Icon::show('account').'Account', 'items' => [
['label' => Icon::show('cogs').' Profile', 'url' => ['/site/signup']],
['label' => Icon::show('sign-out').'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']],
]];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
'encodeLabels' => false,
]);
NavBar::end();
?>
johnitvn
(John Itvn)
July 16, 2015, 8:22am
6
skapeyi:
Try this
<?php
NavBar::begin([
'brandLabel' => 'myRide',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Icon::show('home').'Home', 'url' => ['/site/index']];
$menuItems[] = ['label'=> Icon::show('account').'Account', 'items' => [
['label' => Icon::show('pencil').'Signup', 'url' => ['/site/signup']],
['label' => Icon::show('sign-in').'Login', 'url' => ['/site/login']],
]];
} else {
$menuItems[] = ['label' => Icon::show('home').'Home', 'url' => ['/site/index']];
$menuItems[] = ['label'=> Icon::show('account').'Account', 'items' => [
['label' => Icon::show('cogs').' Profile', 'url' => ['/site/signup']],
['label' => Icon::show('sign-out').'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']],
]];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
'encodeLabels' => false,
]);
NavBar::end();
?>
You are misundertood problem. He asked about set Html in NavBar label not about example.
skapeyi
(Kapeyisamson)
July 17, 2015, 4:59pm
7
He wanted to add an icon to the nav-bar right?
That code there does that, see attached image.