vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   number variables in templates (https://vborg.vbsupport.ru/showthread.php?t=250844)

squishi 09-20-2010 08:04 AM

number variables in templates
 
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 [DATE]1284974502[/DATE] at [TIME]1284974502[/TIME] ---------------

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:

Code:

<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:

Code:

<if condition="$foo = 1"></if>
(but then you'll probably be warned that you might not have wanted to do that).

or maybe

Code:

<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 [DATE]1284994753[/DATE] at [TIME]1284994753[/TIME] ---------------

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.


All times are GMT. The time now is 04:50 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01020 seconds
  • Memory Usage 1,717KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete