Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
in my taxonomy, as presented on the site map, the lists are rendered incorrectly. The output that I'm getting is thus:
<ul>
<li>Top Level 1</li>
<li>Top Level 2</li>
<ul>
<li>Nested Level 2.1</li>
<li>Nested Level 2.2</li>
</ul>
<li>Top Level 3</li>
</ul>
This is not correct; the <ul>
tags need to be rendered within <li>
tags, thus:
<ul>
<li>Top Level 1</li>
<li>Top Level 2</li>
<li><!-- added this <li> here -->
<ul>
<li>Nested Level 2.1</li>
<li>Nested Level 2.2</li>
</ul>
</li>
<li>Top Level 3</li>
</ul>
This of course breaks the xhtml validation for the sitemap page. Easy to fix though! :)
Comments
Comment #1
frjo CreditAttribution: frjo commentedThis code is generated by the function _site_map_taxonomy_tree(). If someone has time to patch that function to make it return valid code I will be happy to commit it.
Sooner or later I will find time to do it myself.
Comment #2
NikLP CreditAttribution: NikLP commentedI've looked at this and it should be very easy, but I can't for the life of me work it out. I'm just up too late I guess.
It would be really cool if this could get fixed, as it's causing 95% of the validation errors on my latest site! :)
Comment #3
zeta ζ CreditAttribution: zeta ζ commentedThis should produce valid code such as;-
Would some one like to review this? I've only changed the foreach () loop but I've printed the whole function here;
Comment #4
NikLP CreditAttribution: NikLP commentedThere's a
</li>
missing in certain places in my taxonomy list with node counts...I'm using taxonomy but not books, but I wouldn't imagine there's any difference between the rendering methods...?
Should be fairly simple to fix I imagine.
Comment #5
zeta ζ CreditAttribution: zeta ζ commentedHi Nik,
Thanks for looking at my code.
I get the same output.
I can't see the missing
</li>
. You show 3 ×<li>
's and 3 ×</li>
's... }:-§ Please see, above the code, the html I'm aiming to produce – slightly different to what you've asked for. I think levels 2.* should be in the same<li>
as level 2. Does it validate?I'm only using this for taxonomy @tm as well.
Comment #6
frjo CreditAttribution: frjo commentedThanks for the code, I will try to test it this week.
A tips is to hand in code in the form of a patch, see http://drupal.org/patch. It makes the code a lot easier to test.
Comment #7
NikLP CreditAttribution: NikLP commentedI checked this a few times - the htmltidy validator in the FF extension says the code is fine, but two other validators including W3C say it's wrong. I now concur with that opinion - I didn't notice what was wrong before.
There is a definite error -
<ul>
's that are nested should be contained within their own<li>
element, so the code above (mine) should read:Basically your code is fine, but your initial "semantic" html (as per your example above your posted code) is not correct :) - see my example at the top of the page for the correct example code.
Comment #8
zeta ζ CreditAttribution: zeta ζ commentedI’ve validated my html with the W3C Markup Validation Service as
Passed all 3.
I’ve also validated this page (I’ve included my html at the end of update #5). It had eight errors, but nothing about lists.
I could only find one example of nested lists on w3c. It did have the nested list in its own
<li>
but the nested list is not semantically part of the preceding<li>
so this is as expected.I find that my html validates, as indicated in update #3, There is definitely not a definite error (nor is there an indefinite error).
How can you say that
? The code produces the ‘semantic’ html, so you contradict yourself.PS Does anyone else bother to type
…
rather than...
, or‘ / ’
rather than boring old'
? Who knew they could?Comment #9
Summit CreditAttribution: Summit commentedSubscribing, will this patch be committed?
greetings, Martijn
Comment #10
Bartezz CreditAttribution: Bartezz commentedSubscribing. Encountered this prob today as well.
Reckon a fix should be committed, yet Zeta's code gives me more errors than the original.
Cheers
Comment #11
Bartezz CreditAttribution: Bartezz commentedI've edited the _site_map_taxonomy_tree function a bit.
This is my first try at writing a patch so comments and improvements are welcome :)
When I've had some feedback to this I will try and post it in the form of a patch!
Nevermind, just use the function in sitemap module 1.2 mine is bogus :)
Comment #12
NikLP CreditAttribution: NikLP commentedThis doesn't make sense... Have you edited this comment, or what?
Besides which, if you post code like that, don't expect anyone to test it - you have to post the PATCH first before anyone will really bother - no point doing it in reverse, it simply won't go anywhere!
Comment #13
Bartezz CreditAttribution: Bartezz commentedYes edited my comment.
And I know about patching but am new to this all and didn't even have a clue as to how to create a patch. Sorry to have tried and share some code in the wrong way...
Comment #14
mcdruidI submitted a patch to fix this issue a little while ago: http://drupal.org/node/231850
Comment #15
mcdruidI believe these three issues are all the same:
#133090: Fails validation due to incorrectly nested lists.
#231850: site_map fails to nest ul's correctly when displaying taxonomy trees
#299014: Wrong syntax in rendered source (HTML validator error) in dept menupoint
I'm marking the last 2 as duplicates of this issue (which is currently marked RTBC), although I've been using the patch I attached to #231850: site_map fails to nest ul's correctly when displaying taxonomy trees for some time, and am happy with it. It's the maintainer's call which patch gets applied, but it would be good to fix this bug one way or another, IMHO.
Comment #16
mcdruidSorry for the blizzard of comments - I've tried to edit the comment above with this extra info, and am getting a strange error (perhaps due to the work ongoing with the project module on d.o?)
If it makes the maintainer's life any easier, I've just checked and my patch http://drupal.org/files/issues/site_map_module_valid_nesting_of_uls_0.patch (from issue 231850) still applies to site_map-5.x-1.x-dev with no errors.
Comment #17
jinjur CreditAttribution: jinjur commentedthis appears to also be an issue in 6.x-1.0 - does that merit a separate ticket, or should that wait on the resolution of this one?
subscribing.
Comment #18
NikLP CreditAttribution: NikLP commentedThis isn't fixed?? Two years to correct a theme error?? Yikes.
Comment #19
frjo CreditAttribution: frjo commentedPatch by mcdruid in http://drupal.org/node/231850 in committed to 6-dev.
Comment #20
mcdruidThanks for applying the patch to the D6 version frjo - any chance you could commit it to the D5 branch too?
Comment #21
kingandy CreditAttribution: kingandy commentedCommitting the patch for 5.0 would be awesome, I just spent half an hour coding this up myself and was about to submit a patch when I found this issue :P