Question about something in template.php

All style (template, theme and imageset) related questions for the new release; advice, feedback here please.
Post Reply
Pests
Registered User
Posts: 8
Joined: Fri Nov 21, 2003 8:50 pm

Question about something in template.php

Post by Pests »

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;
		}

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: Question about something in template.php

Post by Arty »

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.

Pests
Registered User
Posts: 8
Joined: Fri Nov 21, 2003 8:50 pm

Re: Question about something in template.php

Post by Pests »

Yeah, its good. Anyone mind explaining to me a bit more of the layout of $_tpldata?

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

Re: Question about something in template.php

Post by Acyd Burn »

print_r($_tpldata);

;)

Pests
Registered User
Posts: 8
Joined: Fri Nov 21, 2003 8:50 pm

Re: Question about something in template.php

Post by Pests »

Thats going to help, considering Im not using the file anywhere.

metest12
Registered User
Posts: 15
Joined: Fri Jun 20, 2003 5:29 pm

Re: Question about something in template.php

Post by metest12 »

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();
?>

Klors
Registered User
Posts: 95
Joined: Fri Sep 19, 2003 2:08 pm

Re: Question about something in template.php

Post by Klors »

or you could use

Code: Select all

<?php
echo '<pre>';
print_r($_tpldata);
echo '</pre>';
?>

User avatar
DJ P@CkMaN
Registered User
Posts: 10
Joined: Thu Sep 25, 2003 8:55 am

Re: Question about something in template.php

Post by DJ P@CkMaN »

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

Not Radio
Registered User
Posts: 159
Joined: Mon Oct 27, 2003 12:07 am
Contact:

Re: Question about something in template.php

Post by Not Radio »

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.

User avatar
GPHemsley
Registered User
Posts: 1617
Joined: Fri Apr 18, 2003 4:01 am
Location: Long Beach, NY
Contact:

Re: Question about something in template.php

Post by GPHemsley »

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). :|

Post Reply