When using getCriteria() along with buildElementsQuery() raw html gets displayed by the template I am trying to use getCriteria() along with buildElementsQuery () in my plugin in order to eventually modify the query.  At the moment, I am not making any modifications to the query.

But when the the fields are outputted in the template, I ended up getting raw html on the screen.  Not nicely formatted HTML.  For example, the paragraph tag shows as &lt;p&gt; and in the source of the page it is &amp;lt;p&amp;gt;.  The &lt;p&gt; should only be in the source.

How do I get the template to display the nice html and not the raw html?

In my plugin service

public function getMyLibrary()
{
    $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;section = 'library';
    $criteria-&gt;limit = 10;

    return ($criteria-&gt;find());

}


In my template:

{% set my_library = craft.accd.my_library() %}

{% for entry in my_library %} 

    {{ entry.title }}
    {{ entry.body}}

{% endfor %}


Everything works as expected and the rich text html from the body displays correctly.

But when I change it to use buildElementsQuery as I will modifying the query, the entry.title and entry.body get displayed in the template as raw html.

Here is the code with the buildElementsQuery added.  I had to also modify the field body to be field_body in the template.

In my plugin service

public function getMyLibrary()
{
    $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;section = 'library';
    $criteria-&gt;limit = 10;

    $query = craft()-&gt;elements-&gt;buildElementsQuery($criteria);

    return ($query-&gt;queryAll());

}


In my template:

{% set my_library = craft.accd.my_library() %}

{% for entry in my_library %} 

    {{ entry.title }}
    {{ entry.field_body}}

{% endfor %}
$query-&gt;queryAll() returns raw arrays of data from the database, this is why you're needing to prepend field_ to each attribute, to get the column name.

You need to populate some EntryModels before you can use them properly in the templates, with something along the lines of:

$query = craft()-&gt;elements-&gt;buildElementsQuery($criteria);

// modify the query here

$results = $query-&gt;queryAll();

return EntryModel::populateModels($results);