PDA

View Full Version : Trying to understand array's and rendering


Sarcoth
02-11-2010, 01:57 PM
So, I'm trying to convert my mod over to vB4 completely. I have most of it worked out, but now I'm trying to make it easier for the users to update the fields and titles they want to use. In the current version, the user has to go around and update the fields and titles they want to use in multiple places. I want to make it so they only have to do it once. Eventually, I want to make it so they can do it from a vB options page, but I'm taking baby steps. I want to get the variables working first. So, here is what I've done.

//First area is where they set their fields to use and titles//
$field1st = 'field7'; $title1st = "Status"; //1st column
$field2nd = 'field8'; $title2nd = "Character Name"; //2nd column
$field3rd = 'field9'; $title3rd = "VG Char ID"; //3rd column
$field4th = 'field11'; $title4th = "Character Race"; //4th column
$field5th = 'field12'; $title5th = "Adventure Class"; //5th column
$field6th = 'field13'; $title6th = "Adventure Level"; // 6th column
$field7th = 'field14'; $title7th = "Crafing Class"; //7th column
$field8th = 'field15'; $title8th = "Crafting Level"; // 8th column

//Second area is where I convert everything to an array//
$columns = array(
'column1' => $field1st,
'title1' => $title1st,
'column2' => $field2nd,
'title2' => $title2nd,
'column3' => $field3rd,
'title3' => $title3rd,
'column4' => $field4th,
'title4' => $title4th,
'column5' => $field5th,
'title5' => $title5th,
'column6' => $field6th,
'title6' => $title6th,
'column7' => $field7th,
'title7' => $title7th,
'column8' => $field8th,
'title8' => $title8th
);

//This is what I use to render the columns array into the template//
$templater = vB_Template::create('showroster_userbits');
$templater->register('users', $users);
$templater->register('user', $user);
$templater->register('groupsort', $groupsort);
$templater->register('columns', $columns);
$rosterbits .= $templater->render();


The code is a little more indepth than that. $rosterbits goes to $rosterheader and that goes to $SHOWROSTER. The latter is the one that has print_output in case you were wondering.

Anyhow, here is the cool thing. groupsort is used to store the current title being sorted. In the template, if I use the following: {vb:var user.{vb:var groupsort}}, it works perfectly and gives the correct title of the current usergroup.

Also, using {vb:var columns.title1} and {vb:var columns.column1} work fine in the template.

Although, when I try to use {vb:var user.{vb:var columns.column1}}, the spot is blank. I've even replaced var with raw for testing, and it is still blank. I'm not sure what I missed, but I'm sure it is some beginner mistake. Either that, or array's can't be doubled up like a regular variable can be (i.e. {vb:var user.{vb:var groupsort}}).

I can provide the entire code if someone is interested and that is needed to figure out my problem. Thanks for your time.

Lynne
02-11-2010, 08:02 PM
Hmmm, maybe {vb:var user.{$columns[column1]}}

Not really sure, but I'd play around with that.

Sarcoth
02-11-2010, 08:43 PM
Lynne, thank you for giving me the inspiration of adding the brackets. I figured the brackets couldn't be used in the newer way, but this looks to have done the trick. I'll test it out more later and confirm.

{vb:var user.{vb:var columns[column6]}}

Lynne
02-11-2010, 09:13 PM
Oh, that's an interesting way you ended up doing it! I would not have thought of that.

Sarcoth
02-12-2010, 03:51 AM
Thanks, I hope. :) For the record, I did try your way and other similiar ways. That one was the only one that worked though. Fun fun fun, I really enjoy learning this stuff.