Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

How to count taxonomy.findTaxonomy() results?

Started by Muut Archive 11 years ago · 2 replies · 399 views
11 years ago

Hi :)
I want to get the sum of findTaxonomy, then I try this, but it won't work.

TWIG
{% set count = taxonomy.findTaxonomy({'status':'sold'}).maxCount() %}

How is the right way to do the counting?

Thanks
Ray

11 years ago

The best way to resolve these sort of issues is to break them down into small steps.

1) ensure you are getting the pages back from your findTaxonomy() call:

TWIG
{{ dump(taxonomy.findTaxonomy({'status':'sold'})) }}

Look in your messages tab of the debugger (enable it first) to examine the results. If all is good, continue to step 2:

2) this is an array of pages, so you can simply use Twig's length filter to count them:

TWIG
{{ dump(taxonomy.findTaxonomy({'status':'sold'})|length) }}

That should give you the number of found items.

11 years ago

Big thanks! It works now :)
Just get start with GRAV yesterday and I'm loving it

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1329 9 years ago
Archive · by Muut Archive, 9 years ago
2 922 9 years ago
Archive · by Muut Archive, 9 years ago
2 4051 9 years ago
Archive · by Muut Archive, 9 years ago
1 2930 9 years ago
Archive · by Muut Archive, 9 years ago
3 1108 9 years ago