 <p>I would up doing this in a snippet instead:</p> <pre><code> &lt;?php //getgalleryAlbumCover $output = ''; $sql = "select * from modx_gallery_albums mga where mga.id = $id"; $album = $modx-&gt;query($sql); if (!is_object($album)) {return;} $data = $album-&gt;fetch(PDO::FETCH_ASSOC); // just in case ;) $modx-&gt;toPlaceholders($data); $output = $data['cover_filename']; return $output; </code></pre>