atayahmet / laravel-nestable

Laravel 5 nested category/menu generator
MIT License
214 stars 52 forks source link

Add Attributes to <ul> and <li> #2

Closed mostafaznv closed 8 years ago

mostafaznv commented 8 years ago

hi dear @atayahmet i want to add some attributes to <ul> but i didn't see anything in documentation

is it possible in this version? if it's not, how i can add this feature to the package?

edit: i solved this by modifing NestableService.php (only worked for parent ul) i changed renderAsHtml by these codes:

if($first) {
   $tree = $first ? '<ul '.$this->addAttributes().'>' : '';
}

anyway i'm waiting for your update for this package ... i need attributes for <ul> and <li> i have a function to generate ul li for nav-menu so i need dynamic attributes for nested ul and li

atayahmet commented 8 years ago

Hi @mostafaznv

It's important missing. I will add it's features as soon possible.

mostafaznv commented 8 years ago

hi @atayahmet Thanks a lot... I am waiting for new version

atayahmet commented 8 years ago

Hi @mostafaznv

You can already add to < li > attributes.

<?php

Menu::active(function($li, $href, $label) {

    $li->addAttr('class', 'active')->addAttr('data-label', $label);

})->renderAsHtml();

Please check: https://github.com/atayahmet/laravel-nestable#active

I must now add the ability to add attribute feature < ul >

mostafaznv commented 8 years ago

yes i used that yesterday but the problem is that we can't add dynamic classes to < li >

i have a function for generate nav-menu dynamically, and i have multiple menus with different classes

atayahmet commented 8 years ago
<?php

$someClass = 'active-state';

Menu::active(function($li, $href, $label) use ($someClass) {

    $li->addAttr('class', $someClass);

})->renderAsHtml();

Did you try in this way? @mostafaznv

mostafaznv commented 8 years ago

thanks, worked fine ...

atayahmet commented 8 years ago

Ok @mostafaznv, added the feature : 5e072ab

Please update the package and check this: ulAttr

mostafaznv commented 8 years ago

worked but only for parent <ul>

something like this:

<ul class="ul-class">

<li  class="li-class"><a href="#">item</a></li>

<li  class="li-class">

    <a href="#">item</a>

    >>>>>>>>>> <ul> <<<<<<<<<<<<

    <li  class="li-class"><a href="#">item</a></li>

    <li  class="li-class"><a href="#">item</a></li>

    </ul>

</li>

</ul>
mostafaznv commented 8 years ago

i can add attributes to all ul with HTML DOM but i think it's a bad idea... i think it's better to add attributes to all nested tags through the package

atayahmet commented 8 years ago

Hi @mostafaznv update package and try again. 6ea3e48

mostafaznv commented 8 years ago

thanks dear ahmet nested ul fixed but i lost li attributes it seems this code doesn't work:

->active(function($li, $href, $label) use ($liClass) {
   $li->addAttr('class', $liClass);
})
atayahmet commented 8 years ago

Hi @mostafaznv

it fixed. please try again.

mostafaznv commented 8 years ago

wow ... thanks dear @atayahmet

please don't close this thread. i will test the package today and tomorrow and i will report bugs (if i found)

i think your package is the best nested category package for laravel now

mostafaznv commented 8 years ago

thanks @atayahmet i worked with the package and it seems everything are good

atayahmet commented 8 years ago

Hi @mostafaznv

I'm glad to work smoothly. Your welcome.