Add mixed html tag to input text label

matc1
Member | 19
+
0
-

Hi, i'm a novice, i've a question

is it possible to add something like “<i>” and “<b>” in specific part of input text label?

Examples

$form->addText(‘name’, (<b>TEST</b>blablabla <i>TEST2</i>));

I try with Nette\Utils\Html, but how i can't do a mixed html tag like <b> AND <i> different label parts.

Thanks a lot.

Best regards Matteo.

Last edited by matc1 (2019-10-01 11:12)

David Matějka
Moderator | 6445
+
+2
-

Hi, you can either set raw html using

->addText('name', Nette\Utils\Html::el()->setHtml('<b>TEST</b> blabla <i>TEST2</i>'))

(to avoid xss, don't use this approach when part of that html is a user input)

or you can compose the label using multiple Html objects:

$form->addText('name', Nette\Utils\Html::el()
	->addHtml(Nette\Utils\Html::el('b')->setText('abc'))
	->addText('xyz')
	->addHtml(Nette\Utils\Html::el('i')->setText('lorem'))
	->setHtml('<b>TEST</b> blabla <i>TEST2</i>'))
);
matc1
Member | 19
+
0
-

David Matějka wrote:

Hi, you can either set raw html using

->addText('name', Nette\Utils\Html::el()->setHtml('<b>TEST</b> blabla <i>TEST2</i>'))

(to avoid xss, don't use this approach when part of that html is a user input)

or you can compose the label using multiple Html objects:

$form->addText('name', Nette\Utils\Html::el()
	->addHtml(Nette\Utils\Html::el('b')->setText('abc'))
	->addText('xyz')
	->addHtml(Nette\Utils\Html::el('i')->setText('lorem'))
	->setHtml('<b>TEST</b> blabla <i>TEST2</i>'))
);

Perfect Thank's lot.
Best regards
Matteo