nette / utils

🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
https://doc.nette.org/utils
Other
1.98k stars 147 forks source link

Nested HTML elements not working as expected #309

Closed m-ober closed 5 months ago

m-ober commented 5 months ago

Version: 4.0.4

Bug Description

The example (taken from documentation)

$el = Html::el('ul')
    ->create('li', ['class' => 'first'])
        ->setText('hello');
// <ul><li class="first">hello</li></ul>

is not working es expected.

Steps To Reproduce

https://fiddle.nette.org/nette/#1ce0434e2a

The output is: <li class="first">hello</li>

Expected Behavior

According to the docs, the output should be <ul><li class="first">hello</li></ul>

JanTvrdik commented 5 months ago

The documentation is wrong/misleading. You would need to sth like this instead

$ul = Html::el('ul');
$ul->create('li', ['class' => 'first'])->setText('hello');
m-ober commented 5 months ago

Thanks for the response - working with the $ul variable gives the expected result.

dg commented 5 months ago

fixed in documentation