- π¬π§United Kingdom robcarr Perthshire, Scotland
Thanks @jwilson - your template tweak for
views-view-list.html.twig
in 11 worked really well. - Status changed to Active
almost 2 years ago 1:30am 3 February 2023 - πͺπ¨Ecuador jwilson3
Awesome @robcarr!
I'm thinking we could reopen this and switch it to the core Drupal issue queue's Views sub-system.
It was closed years ago by Merlin of Chaos with this reasoning:
Views can't be held responsible for that. There's no really easy way to change that, I don't think, though maybe adding a style directive via theming I think CSS can tell the ordered list what number to start on.
However, the approach in #11 proves that this can (and should) be done really easily with an HTML attribute in the template, not in the theme's CSS.
- π³π±Netherlands Lendude Amsterdam
For the initial question in the IS, isn't this something you would use the 'View result counter' field for? That would not get it right on a HTML level but it would show the correct numbers right?
- πͺπ¨Ecuador jwilson3
IS:
when the ordered (numbered) list option is used and pager displays a second page the items are numbered again from 1 ... rather than continuing at the next higher number. Is there somewhere to change this behaviour?
#15:
isn't this something you would use the 'View result counter' field for?
Sure, you could use view result counter, but not if you want semantic html list. Effectively, if you were to use the ordered (numbered) list option with the view result counter field, then you end up with two sets of numbers, one from the HTML
<li>
itself, and the other from the field value, and as described above, from page two onward the two values would start to diverge. Using view result counter with numbered list would only require further hacking the numbered list functionality to hide the ordinals/bullets in your theme's CSS. This workaround doesn't do any thing for the viability of the numbered list feature out of the box. - Merge request !4415Issue #293295: Views ordered list numbers restart at one when pager used β (Open) created by jwilson3
- Open on Drupal.org βEnvironment: PHP 8.2 & MySQL 8last update
over 1 year ago Waiting for branch to pass - Open on Drupal.org βEnvironment: PHP 8.2 & MySQL 8last update
over 1 year ago Waiting for branch to pass - Status changed to Needs review
over 1 year ago 1:34pm 20 July 2023 - Status changed to Needs work
over 1 year ago 3:32pm 20 July 2023 - πΊπΈUnited States smustgrave
Seems to have a test failure.
Also could the issue summary be updated please
- πͺπ¨Ecuador jwilson3
I cannot make heads or tails of the error. It seems unrelated.
1) Drupal\Tests\system\Functional\Theme\ToolbarClaroOverridesTest::testClaroAssets
Failed asserting that false is true./var/www/html/core/modules/system/tests/src/Functional/Theme/ToolbarClaroOverridesTest.php:141
Line 141 looks like this:
// Confirm toolbar templates are loaded from Claro. $this->assertTrue($this->getSession()->getPage()->find('css', '.toolbar')->hasClass('claro-toolbar'));
We haven't touched anything remotely related to Drupal toolbar in the Claro theme with the changes here.
- last update
over 1 year ago 29,879 pass - π¦πΊAustralia pameeela
This feels like a feature request to me, and something that should be optional. It seems strange to have a page with an ordered list that starts from an arbitrary number? I don't think it's safe to assume that everyone using ordered lists would want it to work that way, which is also supported by the lack of activity on this issue in 15 years.
- πͺπ¨Ecuador jwilson3
I'm having trouble making it all the way to your side to re-classify this as a feature request instead of a bug. (I'd honestly be very interested to see a use case where it makes sense to start ordered, paged output back at 1 on each subsequent page load.) That being said, it is a valid point that this should probably be refactored to be optional, and on by default for new new views, but off by default for existing views, so folks can make a decision whether to opt in on a case-by-case basis.
- π¦πΊAustralia pameeela
I'd honestly be very interested to see a use case where it makes sense to start ordered, paged output back at 1 on
each subsequent page load.I think I just consider each page distinct, but it sounds like you are considering them states of a single page.
I will concede I havenβt used the ordered list formatter very much in my 12+ years of Drupaling but just because it was not needed. I use the results summary far more often. Just anecdotal but could be itβs not widely used generally and thatβs why there isn't much demand for this.
- πͺπ¨Ecuador jwilson3
I think I just consider each page distinct, but it sounds like you are considering them states of a single page.
I havenβt used the ordered list formatter very much
Anecdotally, I've had the need for this several times over the years. So much so that I decided to revive this issue and share my work. I use ordered lists on paged search results, where yes each page in the search results is part of a larger context. This fix is also really helpful when using "Views Load More" or "Views Infinite Scroll" module, where new results are loaded into the current page via ajax without a round trip to the server.
Keep in mind, I'm implementing designs from UX teams with limited knowledge of Drupal, and this pattern of incrementing the index of give search results across pages just makes sense intuitively. It is also worth noting that this issue was closed 16 years ago by Earl, the original author of Views, which could also explain why not more people are subscribed to this issue. The fact that there were 10 comments on the issue after it was originally closed is a decent indicator that there is a need, however small, for this fix.
I rely on the method in #11 (the Twig template override) as the go-to solution on many projects because it is more semantic and properly announced and easily navigable by screen readers, as opposed to having to go with the "views result counter" approach in #15 inside each row and using the "Unformatted" Views display format, which then requires more theming effort to restore basic formatting styles that you get for free with an
<ol>
and<li>
. - π¦πΊAustralia pameeela
Infinite scroll is certainly a good use case :)
I guess I just haven't come across designs for numbered search. I sure wish I could say I was implementing designs from teams with knowledge of Drupal, do those exist? LOL. Just lucky I guess!
- π¬π§United Kingdom catch
Perhaps the implementation approach should be moved out of the template and into a preprocess hook, so that all themes will benefit from this fix.
At one point Wim Leers had a number of issues which were moving logic from preprocess to templates, see [#701667] and #3260399: [meta] Theme/render system cleanup β , which also fits with the way SDCs work. So having the logic in the template might be fine.
This probably needs tests.
This is does need yes.
- π³πΏNew Zealand quietone
This was a random issue for Bug Smash today. It has been recently updated so just adding tag.
- π³π±Netherlands Lendude Amsterdam
Didn't test, but what happens on a View with no pager and you try to use
view.pager.current_page
? Should it check for a pager before using this? And does the Some pager haveview.pager.current_page
?Just looked at existing coverage that might make testing this easier, but alas, there seems to be very little coverage for the list style, just
\Drupal\Tests\views\Kernel\Plugin\StyleHtmlListTest
as far as I could quickly find. No tests for 'ol' list at all.