- Issue created by @KhaledAmer
- 🇷🇺Russia Chi
I want to be get the total number of the view results
Then you need to calculate the results.
Check out Twig length filter.
- 🇩🇪Germany sunlix Wesel
I have the same question. :)
The Twig-Function use the Drupal callableviews_get_view_result()
I have attached a Screenshot with the Details from xdebug.It cant render correctly by Twig. Do you have any advice?
The error is for "0" and "1" the same (In my case there a two view rows)
User error: "0" is an invalid render array key in Drupal\Core\Render\Element::children() (line 98 of core\lib\Drupal\Core\Render\Element.php)
The Result of
Element::children(views_get_view_result('view_name', 'view_display'))
is empty. - 🇷🇺Russia Chi
It cant render correctly by Twig.
What do you expect to be printed? The function returns array of objects and has nothing printable. It's only useful to check if a view has results or not.
- 🇩🇪Germany sunlix Wesel
Yeah you are right. I did not know the function before I saw it here in Twig Tweak.
I think my expectation was mislead by the documentation, where only{{ drupal_view_result('who_s_new', 'block_1') }}
was written down without any further clarification.
So sorry for that. Now it is more clear to me. Ah, same as Sunlix, based on the documentation I was expecting the total result of the page.
Thank alot for the help Chi
A small update about this, I managed to get the total of my views using the following code in my twig template
{{ drupal_view_result('frontpage')|length }}
The reason I want to be able to render it like this is because I want the views count to be visible in my Navbar menu and not in page content.
- Status changed to Fixed
10 months ago 8:29am 5 January 2024 Automatically closed - issue fixed for 2 weeks with no activity.