How can we add a span inside a label ?

How can we reproduce simply this:

<label>my label here <span class="nice">(optional)</span></label>

using label() method ?

No luck with the following options:

<?php echo $form->label($model,'idea', array('<span class="counter"></span>')); ?>

<?php echo $form->label($model,'idea'.'<span>hello</span>'); ?>

This more or less works, but it will also add a very strange "<span…> to the for attribute…

Have anyone accomplish this before ? Please advice…

Hmm well when I need such things, I simply write directly the HTML. Of course you can still get your label text from the model:

<label><?php echo $model->getAttributeLabel('idea'); ?> <span class="nice">(optional)</span></label>

There’s also this question on SO but I haven’t tried it:

Thanks. That is what I will use from now on.

I don’t get that answer. The second block seems to generate two labels, and the first block… well… is just too much mode for accomplish something that should be simple, hence, this is harder to maintain then simply write label tags as you suggest.

Cheers, and thanks for your time.