vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   help with an array in a template (https://vborg.vbsupport.ru/showthread.php?t=318436)

Mickie D 04-26-2015 06:03 PM

help with an array in a template
 
hi there,

I am having trouble with the outputting of an array

Basically I am trying to show the contents of a directory on a custom page. I have created the template and also registered the variable but it will only show me the first row and not the rest.

PHP Code:


$dir 
"/uploaddirectory/";
$exclude = array( ".","..","error_log","_notes" );
if (
is_dir($dir)) {
    
$files scandir($dir);
    foreach(
$files as $file){
        if(!
in_array($file,$exclude)){
            
$filerows '<li>' $file '</li>';

}
}
}

// ###### Register Variables #######


vB_Template::preRegister('mytemplate',array('filerows' => $filerows)); 

There are 4 files in that folder and all that it will display for me is the first one?

Thank you so much for any help you can give me

MarkFL 04-26-2015 06:10 PM

Try this:

PHP Code:

$dir "/uploaddirectory/";
$exclude = array( ".","..","error_log","_notes" );
$filerows '';
if (
is_dir($dir)) {
    
$files scandir($dir);
    foreach(
$files as $file){
        if(!
in_array($file,$exclude)){
            
$filerows .= '<li>' $file '</li>';

}
}
}

// ###### Register Variables #######


vB_Template::preRegister('mytemplate',array('filerows' => $filerows)); 


Mickie D 04-26-2015 06:23 PM

That worked great.

Thank you.

I mistyped something the first time.

Cheers
Sat

kh99 04-26-2015 07:02 PM

If you were seeing one before, adding that '.' before the = shouldn't have made it so you don't see anything. Are you sure you didn't make any other changes? If you just delete the added '.' does the one show up again?

Mickie D 04-26-2015 07:59 PM

Hi KH99 it was my mistake i miss types the template at the bottom! (i edited that post 2 minutes before you posted)

vB_Template::preRegister('mytemplate',array('filer ows' => $filerows));

ALSO :)

just for my sanity it is the DOT EQUALS that explodes it into recursive rows?

And why did you empty the filesrow'' on the third row.

Thanks very much for your help

MarkFL 04-26-2015 09:51 PM

Quote:

Originally Posted by Sparky1000 (Post 2544256)
Hi KH99 it was my mistake i miss types the template at the bottom! (i edited that post 2 minutes before you posted)

vB_Template::preRegister('mytemplate',array('filer ows' => $filerows));

ALSO :)

just for my sanity it is the DOT EQUALS that explodes it into recursive rows?

And why did you empty the filesrow'' on the third row.

Thanks very much for your help

This:

PHP Code:

$variable1 .= $variable2

is shorthand for:

PHP Code:

$variable1 $variable1 $variable2

So this way we are concatenating strings rather than resetting it each time with just "=".


All times are GMT. The time now is 02:32 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.00997 seconds
  • Memory Usage 1,737KB
  • 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
  • (4)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