vBulletin Modifications

arrays and templates

Welcome to vBHackers.com! - vBHackers Updates:

Go Back   vBulletin Modifications > General vBulletin Section > General vBulletin Support

Reply
 
LinkBack Thread Tools
Old 04-05-2006, 05:30 PM   #1
Charter Member
Join Date: Apr 2004
Anubis is on a distinguished road

Default arrays and templates

well, its me again, with some more questions about templates

now, i just wonder, if i have an array with 1 or more rows of data, which is the best way to print it on a template?

well, for being more clear, lets suppose im reading seveal data from a table, and im getting an array with all the data, like userid, user favorite url, user fav coulor and stuff, on plain php, i would use a while to print this, using the data on the array, something like

You must first be a registered member to view any code.
and go on, taking out all my data, using the properly <table> tags and derivates to give it a shape, but, what if i wanted to do this on a template? how can i print this on a template?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 04-05-2006, 06:36 PM   #2
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

You'll have to use the so called "bits". Here's a real simple example:

You must first be a registered member to view any code.
Note the change from $isdata to $isdatas.
In the while function you'll have to use $isdata[something], and it will show the [something] field of the row its parsing at that time.

The isdatalistbit template would look kinda like this:
You must first be a registered member to view any code.
And it will output the above template with different information for every row X amount of times, where X is the number of rows.

Than below the ending of the condition you'll have to call for the "shell" template, where you must put:

You must first be a registered member to view any code.
Ofcourse, for the sake of clarity I only included a very, very basic "bit". A good way to study bits is to open up the postbit template and the showthread.php file of 3.0.x, thats how I learned most of it ;).

Hope this helps! If you have any other questions or questions about this post, don't hesitate to ask ;).
__________________
Need some custom work done for your site, but can't find a (freelance) coder willing to take on the job? Good news: you needn't look further, as I'm currently accepting custom jobs! From a template fix to a completely new portal system, you name it and I'll make it exclusively for your site! Interested? Send me a PM for details. ;)


Please note that I will only provide support through the vBHackers.com Forums, not through MSN/email/PM.

Last edited by Arnoud; 04-05-2006 at 06:43 PM..




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-05-2006, 08:17 PM   #3
Charter Member
Join Date: Apr 2004
Anubis is on a distinguished road

Default

0k, thank you for your answer, now, if i want to include $isdatabits inside the main template named MAIN_DATA

do i have to to put the "isdatabits" on the $globaltemplates = array( ) option in the php file? or i need to also put it somewhere else?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-05-2006, 08:58 PM   #4
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Quote:
Originally Posted by Anubis
0k, thank you for your answer, now, if i want to include $isdatabits inside the main template named MAIN_DATA

do i have to to put the "isdatabits" on the $globaltemplates = array( ) option in the php file? or i need to also put it somewhere else?
Nope, if you were to include that in a template your code would look a little like this:

You must first be a registered member to view any code.
And you'd have to include the "isdatalistbit" in your $actiontemplates() array, else it would take up an extra query.

I'm not quite sure what you mean by include in the template though, you mean display the information, right?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-05-2006, 09:05 PM   #5
Charter Member
Join Date: Apr 2004
Anubis is on a distinguished road

Default

well, what i mean is

i have MAIN_DATA as the main template for the program, the template showed up when i get into www.myforum.com/board/main.php, in other words, when i access the php im codding, MAIN_DATA is the main template used, so, i want to show $isdatalistbit when MAIN_DATA is displayed on the browser




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-05-2006, 09:25 PM   #6
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Quote:
Originally Posted by Anubis
well, what i mean is

i have MAIN_DATA as the main template for the program, the template showed up when i get into www.myforum.com/board/main.php, in other words, when i access the php im codding, MAIN_DATA is the main template used, so, i want to show $isdatalistbit when MAIN_DATA is displayed on the browser
Right, than the above code will do.

Btw, you can also replace
You must first be a registered member to view any code.
with

You must first be a registered member to view any code.
sothat the code becomes:

You must first be a registered member to view any code.
That however hard codes your "bit" (which is a bad thing), but it might help you understand a bit better how the bits work.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-06-2006, 06:12 PM   #7
Charter Member
Join Date: Apr 2004
Anubis is on a distinguished road

Default

the replacwmwnt you're suggesting, im supposed to then have something like this?

You must first be a registered member to view any code.
and use $isdata $isdata2 $isdata3 and such on the main template? or i just need to use the same variable $isdata with all the array data?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-06-2006, 06:30 PM   #8
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Quote:
Originally Posted by Anubis
the replacwmwnt you're suggesting, im supposed to then have something like this?

You must first be a registered member to view any code.
and use $isdata $isdata2 $isdata3 and such on the main template? or i just need to use the same variable $isdata with all the array data?
That's nearly right ;).

This is the code you need:

You must first be a registered member to view any code.
Say you have 2 users in your user table. One is called "Matt", with the userid "1". His fav_url is set to "http://www.vbhackers.com", and his fav_coulor is set to "red".
Then there's "Tedd", he's got the userid "2". His fav_url is set to "http://www.flosoft.biz", and his fav_coulor is set to "Blue". With this information the above could would output:

You must first be a registered member to view any code.
If there would be a third user with userid 3, a fav_url of "http://www.vbulletin.org" and a fav_coulor of Pink it'd be the following:
You must first be a registered member to view any code.
As you can see, it's not very clear but it should do as an example. Once you understand that concept you can move onto using templates, allowing you to add more complex features like an html comment (<!-- -->), which is useful for debugging.

A vital element of this method which you must understand is the ".=". This is very different from the "=", as ".=" basicly adds to the value. It's quite hard to explain, but I guess you understand from the above code.

If you don't understand something, or have something else you'd like to ask please do post it.. we're here to help ;).

EDIT: Oh, and, with the above code you'd simply need to add "$isdatabits" to the template in order to output the above code.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-06-2006, 06:59 PM   #9
Charter Member
Join Date: Apr 2004
Anubis is on a distinguished road

Default

guy, you're a genius!

this worked for me quet good

that one about the ".=" thing is something new for me, is php standar? or is something into vbulletin own codding?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-06-2006, 07:02 PM   #10
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Hehe, thank you and no problem .

".=" is indeed a default PHP feature. I'm not sure in which PHP version this was introduced, as I've used it for as long as I can remember. ;)




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -3. The time now is 06:40 PM.

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc. (Patent Pending)