Logic/Presentation separation
&lt;?php
    // this code goes into your controller
    $visitor_rows = [];

    // lets do all the hard work here
    while($visitor = $visitors-&gt;fetch_object()) {
        $time = $visitor-&gt;time;
        $visitor = new User($visitor-&gt;viewer_id);
        $visitor_rows[] = [
            'id' =&gt; $visitor-&gt;id,
            'profile_image' =&gt; $visitor-&gt;profile_image,
            'name' =&gt; $visitor-&gt;name,
            'time' =&gt; $time-&gt;convertToAgo($time),
        ]);
    }

    // the template only needs to know about $visitor_rows now
?&gt;


&lt;!-- the template is now a lot simpler to follow and understand --&gt;
&lt;!-- i prefer the foreach: endforeach; loop syntax when embedded in html --&gt;
&lt;div id="page-content"&gt;
    &lt;div class="container-fluid"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-lg-11"&gt;
                &lt;div id="featured_users"&gt;&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-lg-11"&gt;
                &lt;h1&gt; Visitors &lt;/h1&gt;
                &lt;?php foreach ($visitor_rows as $row): ?&gt;
                    &lt;?= $this-&gt;insert('visitors/visitor', $row) ?&gt;
                &lt;?php endforeach ?&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;