PDA

View Full Version : number variables in templates


squishi
09-20-2010, 08:04 AM
In the newattachmentbit template, I want to give every upload a number.
In php, I would just use a variable and increment it for every uploaded attachment.
How do I do this in a vbulletin template?

--------------- Added 1284974502 at 1284974502 ---------------

I realize this could be done easily by using an ordered list in the newattachmentbit template instead of those ancient tables.

I just tried it out with the list. It has not the effect that I want, though.
If I use a list and remove the first uploaded attachment in the list, the list gets renumbered.
I want the numbers to remain the same after removing an image from the list.
Because I sometimes get requests like "attachment 1,4,13,25 should be removed". If the pics get renumbered, it creates a mess.

So I must use an incrementing variable to achieve this.

kh99
09-20-2010, 09:56 AM
I saw this idea a while ago in a mod - you can use the side-effect of an if condition to increment a counter, like:

<if condition="++$foo"></if>
$foo // foo is 1

<if condition="++$foo"></if>
$foo // foo is 2

squishi
09-20-2010, 01:00 PM
Thanks for the info, kh99. That is very useful.
Is there also a way to initialize the variable first? Because the above is not strictly correct. It would probably fill my php errors log files pretty quickly.

kh99
09-20-2010, 01:30 PM
Yeah, I think you can do:

<if condition="$foo = 1"></if>

(but then you'll probably be warned that you might not have wanted to do that).

or maybe

<if condition="($foo = 1) == 1"></if>

would get rid of any warning.

(I haven't tried these)

BTW, what's not strictly correct about the one above, just the fact that it's not initialized? If the problem is that it's not initlaized before it's used anywhere at all, then I guess the only thing you can do is initialize it in a plugin (or use some existing variable)

squishi
09-20-2010, 01:47 PM
Good stuff, kh99. I'll try it out.

--------------- Added 1284994753 at 1284994753 ---------------

I tried it out. Unfortunately, it shows the same behavior as the ordered list.
When I remove one of the attachments, the others get renumbered.
I would like the original numbers to stay the same.