Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with variables

Status
Not open for further replies.

stacybk

Programmer
Joined
Oct 22, 2003
Messages
15
Location
US
I have the following piece of code.

$template->assign_block_vars('topicrecentpopular', array(
'TOPICSPOPULAR' => $poppost,
'TOPICSPOPULARC' => $poppostc,
'TOPICSPOPULARVIEW' => $popviewpost,
'TOPICSPOPULARVIEWC' => $popviewpostc,
'TOPICSRECENT' => $lastpost)
);

If I change topicrecentpopular to another name like stacy and then change it in the one other place I have it, I get no data. topicrecentpopular is not declared anywhere, so I don't understand why php would mind if it had a different name.

Any ideas? Thanks.
 
This is the function. Does that help?

function assign_block_vars($blockname, $vararray)
{
if (strstr($blockname, '.'))
{
// Nested block.
$blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1;
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']';
}
// 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;';

// Now we evaluate this assignment we've built up.
eval($str);
}
else
{
// Top-level block.
// Add a new iteration to this block with the variable assignments
// we were given.
$this->_tpldata[$blockname . '.'][] = $vararray;
}

return true;
}
 
Define &quot;get no data&quot;. How are you verifying that the data you want is not there?

If you invoke the class method the way you want then perform

print_r ($template->_tpldata);

Do you see your array data there?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
With the code as originally written, the data comes out in a table. When I change the variable name, the table is blank. I will try that command and see what happens, though.
Btw, I am not just changing the variable name to change it, if I figure this out, it will solve a different problem as well.
 
when I use the print_r command, I see that the data is there exactly the same way with both names. I will have to figure out why the template is not outputting the second version.

Thanks for your help. I will post again with information about the output if I can't get it.
 
Problem solved. It turns out that the comment that came right before the code that output that array to the table needed to be written with the name of the array in it. So, changing the name of the array and not changing the comment screwed everything up.

Thank you sleipnir24 for your help. I wouldn't have found the problem without following some of your suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top