2

I just started with the Yii framework using the bootstrap theme; everything is awesome, except that I can't find a way of naming attributes in bootstrap widgets. For instance site has a chat button, how do i access it by jQuery('#id')?

I tried adding in the id attribute of the same array as follows:

<?php $this->widget('bootstrap.widgets.TbButton',array(
    'buttonType'=>'link',
    'icon' => 'icon-user icon-white',
    'type'=>'info',
    'label'=>'Live chat',
    'url'=>'javascript:switchChat();',
    'id'=>'chatPopup'
    )); ?>

Ok, after little head scratching i found out about htmlOptions array and itemOptions :)

Ok finally got there

        'class'=>'bootstrap.widgets.TbMenu',
        'items'=>array(
            array('label'=>'Home', 'url'=>array('/site/index')),
            array('label'=>'Messages ()',
                  'url'=>array('/site/messages'),
                  'visible'=>!Yii::app()->user->isGuest,
                  'itemOptions'=>array('class'=>'msgcnt'),
            ),

But this doesn't generate attributes for me, except the standard url, type, etc.

So the only way I am currently able to do this is by placing widgets within div wrappers with ids, but how would I deal with those widgets where div is unacceptable, for example in the case of a navbar?

madth3
  • 7,275
  • 12
  • 50
  • 74
user2013697
  • 157
  • 1
  • 2
  • 8
  • You set id by `'id'=>'chatPopup'`, you dont have that id in your generated html? –  Jul 04 '13 at 12:11

1 Answers1

6

You can set attributes through the htmlOptions property:

<?php $this->widget('bootstrap.widgets.TbButton',array(
    // ..
    'htmlOptions' => array(
        'id' => 'myid',
    ),
));?>
Michael Härtl
  • 8,428
  • 5
  • 35
  • 62