Loading...
 
Features / Usability

Features / Usability


Counting total files in files gallery

posts: 8429 Israel

I need to count all the files from one or several files galleries using the wikiplugin list in a smarty template.

If I use the usual {output template=count} it count just the object not the object inside.

IE: I have 3 sub-galleries with a total of 8 pictures.

Gallery pictures (id1)
--Gallery 2019
---- file1
---- file2
---- file3
-- Gallery 2020
---- file4
---- file5
---- file6
-- Gallery 2021
---- file7
---- file8


If I use {filter content="1" field="gallery_id"} it will return "3" but what I’m looking for is the files count "8".

I could hardcode each gallery_id and create an addition of results but it will be fragile and... dull.

Is there a smart way to ?

posts: 126760 United Kingdom

Hi B

Nice puzzle!

I think i would do the following:

  • Smarty capture the output of list:
    • type = filegallery
    • gallery_id = 1
    • output object_id + " or "


...so you end up with a string containing (for example) "4 or 5 or 6 or "

  • Then do another plugin list with:
    • type = file
    • gallery_id = "4 or 5 or 6 or " + "1" (i.e. the string you captured above with the parent galleryId added on the end)
    • output whatever you need from the files


Does that make sense?

posts: 8429 Israel

Yes that make sense, thank you.

Was kind’of plan B as I had hope we have a nice Plan A.

… When we rebuilt the index we have a number of files calculated I had hope I can refactor part of the code.

posts: 126760 United Kingdom

If you just want to count all the files and don't care where they are then just filter by that:

{LIST()}
  {filter type="file"}
{LIST}


e.g.