phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

Question about something in template.php

All style (template, theme and imageset) related questions for the new release; advice, feedback here please.

Question about something in template.php

Postby Pests » Fri Nov 21, 2003 8:54 pm

Not too sure if this would be the place to post this, but I guess it is related to the styling...

Was looking over the source of template.php and found this, can someone tell me what it does? I think I have a pretty good idea, but it might be wrong due to my lack of knowledge of $_tpldata array.

Code: Select all
if (strstr($blockname, '.'))
      {
         // Nested block.
         $blocks = explode('.', $blockname);
         $blockcount = sizeof($blocks) - 1;

         $str = &$this->_tpldata;
         for ($i = 0; $i < $blockcount; $i++)
         {
            $str = &$str[$blocks[$i]];
            $str = &$str[sizeof($str) - 1];
         }

         // Now we add the block that we're actually assigning to.
         // We're adding a new iteration to this block with the given
         // variable assignments.
         $str[$blocks[$blockcount]][] = $vararray;
      }
Pests
Registered User
 
Posts: 8
Joined: Fri Nov 21, 2003 8:50 pm

Re: Question about something in template.php

Postby Arty » Sat Nov 22, 2003 12:04 pm

This code assigns variables to block if block is nested.

> if (strstr($blockname, '.'))

Checks if there is dot in block name

> $blocks = explode('.', $blockname);

Splits it to array of block names

> $blockcount = sizeof($blocks) - 1;

get number of blocks

> $str = &$this->_tpldata;

variable $str points to $this->_tpldata

> $str = &$str[$blocks[$i]];

$str points to block array

> $str = &$str[sizeof($str) - 1];

$str points to last item in array.

by this time if variable name was block1.block2.block3 then $str points to last item in block2

> $str[$blocks[$blockcount]][] = $vararray;

adds one more item to block array.

I hope this explanation is clear enough.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: Question about something in template.php

Postby Pests » Sat Nov 22, 2003 5:40 pm

Yeah, its good. Anyone mind explaining to me a bit more of the layout of $_tpldata?
Pests
Registered User
 
Posts: 8
Joined: Fri Nov 21, 2003 8:50 pm

Re: Question about something in template.php

Postby Acyd Burn » Sat Nov 22, 2003 8:02 pm

print_r($_tpldata);

Wink
User avatar
Acyd Burn
Server Manager
 
Posts: 1838
Joined: Tue Oct 08, 2002 5:18 pm
Location: Behind You

Re: Question about something in template.php

Postby Pests » Sun Nov 23, 2003 4:11 pm

Thats going to help, considering Im not using the file anywhere.
Pests
Registered User
 
Posts: 8
Joined: Fri Nov 21, 2003 8:50 pm

Re: Question about something in template.php

Postby metest12 » Mon Nov 24, 2003 9:54 pm

Just using print_r() prints everything on one line (which on my opinion is hard to read)!
Try this:

Code: Select all
<?php
print(nl2br(print_r($_tpldata, true)));
// Unset it
unset($tpldata_info);
?>


If the parentheses are confusing:

Code: Select all
<?php
$tpldata_info
= print_r($_tpldata, true);
$tpldata_info = nl2br($tpldata_info);
print(
$tpldata_info);
// Unset it, just in case something else uses that var
unset($tpldata_info);
?>


And if you want nothing but the print_r(), do this:

Code: Select all
<?php
$tpldata_info
= print_r($_tpldata, true);
$tpldata_info = nl2br($tpldata_info);
print(
$tpldata_info);
// No unsetting here, as we're exiting anyway
exit();
?>
metest12
Registered User
 
Posts: 15
Joined: Fri Jun 20, 2003 5:29 pm

Re: Question about something in template.php

Postby Klors » Tue Nov 25, 2003 11:32 pm

or you could use
Code: Select all
<?php
echo '<pre>';
print_r($_tpldata);
echo '</pre>';
?>
Klors
Registered User
 
Posts: 95
Joined: Fri Sep 19, 2003 2:08 pm

Re: Question about something in template.php

Postby DJ P@CkMaN » Tue Dec 23, 2003 5:12 am

Or
Code: Select all
header('Content-Type: text/plain');
die( print_r($_tpldata, 1) );
Cameron Daniel :: SmallNothings Admin, SitePoint Forums Mentor
SmallNothings - Love, Lust & Relationships
SitePoint Forums
User avatar
DJ P@CkMaN
Registered User
 
Posts: 10
Joined: Thu Sep 25, 2003 8:55 am

Re: Question about something in template.php

Postby Not Radio » Tue Dec 23, 2003 6:47 am

metest12 wrote:Just using print_r() prints everything on one line (which on my opinion is hard to read)!


Incorrect. It prints it out with newlines, but not HTML br tags.
Not Radio
Registered User
 
Posts: 159
Joined: Mon Oct 27, 2003 12:07 am

Re: Question about something in template.php

Postby GPHemsley » Thu Dec 25, 2003 5:04 pm

Not Radio wrote:
metest12 wrote:Just using print_r() prints everything on one line (which on my opinion is hard to read)!


Incorrect. It prints it out with newlines, but not HTML br tags.

Which means "everything on one line" when you're viewing the final page (not the source). Neutral
User avatar
GPHemsley
Registered User
 
Posts: 1617
Joined: Fri Apr 18, 2003 4:01 am
Location: Long Beach, NY


Return to [3.0/Olympus] Styling

Who is online

Users browsing this forum: No registered users and 6 guests