vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   {vb:each} loop count... (https://vborg.vbsupport.ru/showthread.php?t=242767)

civil78 05-18-2010 07:48 AM

{vb:each} loop count...
 
Is there any way to find how many loops makes the vb:each in a template?

For example I want to do something like this

HTML Code:

<vb:each from="arrayname" key="keyid" value="data">
        <vb:if condition="$loops>=4">
                Some HTML CODE
        <vb:else />
                Some Other HTML CODE
        </vb:if>
</vb:each>

Thanks

civil78 05-27-2010 07:29 AM

I know this is the stupid way but it works :)

HTML Code:

<vb:if condition="$count = 0"></vb:if>

<vb:each from="array" key="arraykey" value="arrayvalue">

        <vb:if condition="$count = $count + 1"></vb:if>
       
        <vb:if condition="$count <= 3">
       
                <!-- YOUR HTML -->
                       
        <vb:else />
       
                <!-- YOUR HTML -->
               
        </vb:if>

</vb:each>

Somehow when you put php code inside <vb:if condition="">, the code executed.

If anyone knows other way (exept javascript) please tell me.

smnet 01-17-2011 12:15 PM

Quote:

Originally Posted by civil78 (Post 2043979)
I know this is the stupid way but it works :)

HTML Code:

<vb:if condition="$count = 0"></vb:if>

<vb:each from="array" key="arraykey" value="arrayvalue">

        <vb:if condition="$count = $count + 1"></vb:if>
       
        <vb:if condition="$count <= 3">
       
                <!-- YOUR HTML -->
                       
        <vb:else />
       
                <!-- YOUR HTML -->
               
        </vb:if>

</vb:each>

Somehow when you put php code inside <vb:if condition="">, the code executed.

If anyone knows other way (exept javascript) please tell me.

Edit:.... ok, it works.... it's just+not ideal!!

Retal 01-18-2011 05:20 PM

You could also use an array with numeric keys, if you can guarantee that the keys are continuous.

PHP Code:

$array = ('A''B''C''D');
unset(
$array[2]);
...
$array array_values($array); 


smnet 01-18-2011 08:42 PM

It looks like a built in method will be added into a future vBulletin version....

Check this out and don't forget to VOTE
http://tracker.vbulletin.com/browse/VBIV-10883

zlos 01-27-2011 09:34 AM

Vote added.


All times are GMT. The time now is 07:14 AM.

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.01099 seconds
  • Memory Usage 1,729KB
  • 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_html_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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