Not Solved Template looping excessively when used in a while loop
#1
Not Solved
I have 2 templates evaluated in a while loop. The parent template ($Comments) loops normally but the child template ($Delete) shows once in the first comment, twice in the next and 3 times in the 3rd comment...The $delete variable is placed in the comment template. I want the delete comment button to show up after each comment so taking out the $delete variable from the comment template makes 3 delete comment buttons show up together. Please how do I fix this?
$Delete = "";
$Comment = "";
while($result = $db->fetch_array($query))
{
     $id = $result['tid'];
     $Msg = $result['comment'];
     eval("\$Delete .= \"".$templates->get("delete_comment")."\";");
     eval("\$Comment .= \"".$templates->get("comments")."\";");
}
Inside the comment template:
Comment: {$Msg} {$Delete}
Reply
#2
Not Solved
Evaluating 2 templates in a while loop makes one of the variables appear multiple times than necessary. To circumvent that, I avoided using the template in the php page and passed the html form directly to the variable. But the variables are not being executed ($comment shows up as $comment on the page).
$Delete = '<form action="{$user_profile}" method="post" >
 <input type="hidden" name="message" value="{$comment}" />
<input type="hidden" name="act" value="commentus-delete" />
<input  type="submit" class="button" name="Delete_Comment" value="Delete Comment"/>

</form>' ;
Reply
#3
Not Solved
(2017-12-17, 06:41 PM)Dorian58 Wrote: Evaluating 2 templates in a while loop makes one of the variables appear multiple times than necessary. To circumvent that, I avoided using the template in the php page and passed the html form directly to the variable. But the variables are not being executed ($comment shows up as $comment on the page).
$Delete = '<form action="{$user_profile}" method="post" >
 <input type="hidden" name="message" value="{$comment}" />
<input type="hidden" name="act" value="commentus-delete" />
<input  type="submit" class="button" name="Delete_Comment" value="Delete Comment"/>

</form>' ;

If you enclose it in single quotes, you have to write it this way:

$Delete = '<form action="'.$user_profile.'" method="post" >
 <input type="hidden" name="message" value="'.$comment.'" />
<input type="hidden" name="act" value="commentus-delete" />
<input  type="submit" class="button" name="Delete_Comment" value="Delete Comment"/>
</form>' ;
Reply
#4
Not Solved
Thanks Doyle. It worked. Any reason why a template in a while loop evaluates multiple times than necessary?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)