what could be better for respect the MVC?
make a view with a for loop like this:
<?php foreach($posts as $post){
echo '<div class="post">'.$post.'</div>';
}
?>
where $posts hold all the body of the post.
or in the controler make something like this:
<?php foreach($posts as $post){
$html = $html + '<div class="post">'.$post.'</div>';
}
?>
then pass the $html to the view and display them.
Simple logic such as loops are acceptable in views, you don’t want any business logic in there. Since the logic of this loop is for display purposes, I would use the first.
Generally in template files, the foreach: endforeach syntax is used.
Or if short tags are enabled (Please note that this is often disabled on production servers, but <?php cannot be disabled, so I’d recommend the above method):
However this is a convention as opposed to a rule.