First of all you're doing the repeat your mistake of overwriting theatoirtap wrote:Code: Select all
$row =& $rowset[$post_list[$i]]; $poster_id = $row['user_id']; // Create the SQL statement $sql= 'SELECT post_id FROM phpbb_posts WHERE topic_id= '. (int)$topic_id; $result= $db-> sql_query( $sql ); while( $row= $db-> sql_fetchrow( $result ) ) {
$row
variable. Stop that.- Second: why would you want to assign your output globally, instead of per post? That's most likely the wrong decision and it proves you yet didn't understand how loops are working.
- Third: handing over data to the template must follow the hierarchy: you can't assign iterations of another loop while haven't assigned the current iteration of the parent loop. That's the reason why you won't see
assign_block_vars()
in the wild, but instead at the end of the big loop in /viewtopic.php:Code: Select all
// Dump vars into template $template->assign_block_vars('postrow', $postrow); if (!empty($cp_row['blockrow'])) { foreach ($cp_row['blockrow'] as $field_data) { $template->assign_block_vars('postrow.custom_fields', $field_data); } } // Display not already displayed Attachments for this post, we already parsed them. ;) if (!empty($attachments[$row['post_id']])) { foreach ($attachments[$row['post_id']] as $attachment) { $template->assign_block_vars('postrow.attachment', array( 'DISPLAY_ATTACHMENT' => $attachment) ); } }
- Fouth: loop variables can't have underscores.
- Last but not least: use proper HTML.
Let's start fresh. Undo all changes you made and open /viewtopic.php. Find:
Code: Select all
$row =& $rowset[$post_list[$i]];
$poster_id = $row['user_id'];
Code: Select all
// My block
$sql= 'SELECT post_id
FROM phpbb_posts
WHERE topic_id= '. (int)$topic_id;
$result= $db-> sql_query( $sql );
$aMyblock= array(); // Store in variable, instead of feeding the template instantly
while( $row2= $db-> sql_fetchrow( $result2 ) ) { // You see that? Another variable than "$row"
$aMyblock[]= array( 'TPL_VAR' => $row2['post_id'] );
}
$db-> sql_freeresult( $result );
Code: Select all
// Dump vars into template
$template->assign_block_vars('postrow', $postrow);
if (!empty($cp_row['blockrow']))
{
foreach ($cp_row['blockrow'] as $field_data)
{
$template->assign_block_vars('postrow.custom_fields', $field_data);
}
}
// Display not already displayed Attachments for this post, we already parsed them. ;)
if (!empty($attachments[$row['post_id']]))
{
foreach ($attachments[$row['post_id']] as $attachment)
{
$template->assign_block_vars('postrow.attachment', array(
'DISPLAY_ATTACHMENT' => $attachment)
);
}
}
Code: Select all
foreach( $aMyblock as $aBlock ) { // Now is okay
$template-> assign_block_vars( 'postrow.myblock', $aBlock ); // No underscore
}
Code: Select all
<h3 <!-- IF postrow.S_FIRST_ROW -->class="first"<!-- ENDIF -->><!-- IF postrow.POST_ICON_IMG --><img src="{T_ICONS_PATH}{postrow.POST_ICON_IMG}" width="{postrow.POST_ICON_IMG_WIDTH}" height="{postrow.POST_ICON_IMG_HEIGHT}" alt="" /> <!-- ENDIF --><a href="#p{postrow.POST_ID}">{postrow.POST_SUBJECT}</a></h3>
<p class="author"><!-- IF S_IS_BOT -->{postrow.MINI_POST_IMG}<!-- ELSE --><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a><!-- ENDIF -->{L_POST_BY_AUTHOR} <strong>{postrow.POST_AUTHOR_FULL}</strong> » {postrow.POST_DATE} </p>
Code: Select all
<p>Output = <!-- BEGIN myblock --> {postrow.myblock.TPL_VAR} <!-- END myblock --></p>