We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Mark Huot file extension - COUNT problem...

Development and Programming

Paul_B's avatar
Paul_B
86 posts
16 years ago
Paul_B's avatar Paul_B

Hi

I’m using the file extension to allow users to upload multiple images at once. I need to use a switch in the outputted template to assign a class to every third image, but for some reason the last image in the array resets the count to 1.

So if I upload three images, the output

{count}

reads 1,2,1

The switch is also therefore affected - if I have

class="{switch="classone|classtwo|classthree"}"

the output goes classone, classtwo, classone

Can anyone help? I’ve looked at the source code but the only relevant line I can find is this:

'count' => $count+1,

Thanks in advance 😊

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

There’s been lots of glitches regarding counts with the extension, especially when you add more files later on or delete some. The best workaround has been to use PHP to do the counting.

       
Paul_B's avatar
Paul_B
86 posts
16 years ago
Paul_B's avatar Paul_B

Hi slapshotw - thanks for getting back to me. I recently came to that conclusion and wrote some php to get around the problem 😊

       
bigmikestudios's avatar
bigmikestudios
22 posts
16 years ago
bigmikestudios's avatar bigmikestudios

Hey,

I had the same problem, and I think I have found a solution. I think the trouble occurs in the lines where the array is flipped and flipped back again.

I changed line 1223 from:

'count' => $count+1,

to

'count' => $count,

and after line 1237, which reads:

$var = array_flip($var);

I added:

$var['{count}']++;
       
Neil Evans's avatar
Neil Evans
1,374 posts
16 years ago
Neil Evans's avatar Neil Evans

I vouch for the above method - it worked for me… Now to resolve why when uploading multiple images at once it overwrites them all with the same image!

       
notacouch's avatar
notacouch
92 posts
16 years ago
notacouch's avatar notacouch

Above method works so far with one caveat for me however: Can no longer use the count consistently as a conditional.

E.g. in:

{if count == #} ...

The count in {if count} will be 1 less than {count}. So to keep things consistent you should resort to:

{if "{count}" == "#"} ...
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.