vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   implementing php function and an array into a template (https://vborg.vbsupport.ru/showthread.php?t=281218)

egysc 04-06-2012 11:02 PM

implementing php function and an array into a template
 
how can I implement a php function and an array into a template some thing similar to :
PHP Code:

<?php
function draw_rand_array($array,$draws)
{
        
$lastIndex count($array) - 1;
        
$returnArr = array();
        while(
$draws 1)
        {
                
$rndIndex rand(0,$lastIndex);
                
array_push($returnArr,array_splice($array,$rndIndex,1));
                
$draws--;
                
$lastIndex--;
        }

        return 
$returnArr;
}
?>


kh99 04-06-2012 11:40 PM

You can't put php in a template, it has to go in a plugin. You can then register a variable (in your plugin code) to a template to display it. In the case of an array, you can then use <vb:each> tags in the template like:

Code:

<vb:each from="myarray" value="item">
//Code to display an item
{vb:raw item}
</vb:each>


For instructions on registering variables to a template, you can look at this article: https://vborg.vbsupport.ru/showthread.php?t=228078 . If you are trying to use your array in an existing template, you will want to use the vB_Template::preRegister() function.


All times are GMT. The time now is 10:46 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.00927 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
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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