Answers.Body: <p><code>$query-&gt;queryAll()</code> returns <em>raw</em> arrays of data from the database, this is why you're needing to prepend <code>field_</code> to each attribute, to get the column name.</p>
  
  <p>You need to populate some <code>EntryModels</code> before you can use them properly in the templates, with something along the lines of:</p>
  
  <pre><code>$query = craft()-&gt;elements-&gt;buildElementsQuery($criteria);
  
  // modify the query here
  
  $results = $query-&gt;queryAll();
  
  return EntryModel::populateModels($results);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-03T16:26:52.667Z
Answers.LastActivityDate: 2015-03-03T16:26:52.667Z
Answers.UserDisplayName: Mike Pepper
Body: <p>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.</p>
  
  <p>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 <code>&lt;p&gt;</code> and in the source of the page it is <code>&amp;lt;p&amp;gt;</code>.  The <code>&lt;p&gt;</code> should only be in the source.</p>
  
  <p>How do I get the template to display the nice html and not the raw html?</p>
  
  <p>In my plugin service</p>
  
  <pre><code>public function getMyLibrary()
  {
      $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
      $criteria-&gt;section = 'library';
      $criteria-&gt;limit = 10;
  
      return ($criteria-&gt;find());
  
  }
  </code></pre>
  
  <p>In my template:</p>
  
  <pre><code>{% set my_library = craft.accd.my_library() %}
  
  {% for entry in my_library %} 
  
      {{ entry.title }}
      {{ entry.body}}
  
  {% endfor %}
  </code></pre>
  
  <p>Everything works as expected and the rich text html from the body displays correctly.</p>
  
  <p>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.</p>
  
  <p>Here is the code with the buildElementsQuery added.  I had to also modify the field body to be field_body in the template.</p>
  
  <p>In my plugin service</p>
  
  <pre><code>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());
  
  }
  </code></pre>
  
  <p>In my template:</p>
  
  <pre><code>{% set my_library = craft.accd.my_library() %}
  
  {% for entry in my_library %} 
  
      {{ entry.title }}
      {{ entry.field_body}}
  
  {% endfor %}
  </code></pre>
  
Tags: <plugin-development><templating>
Title: When using getCriteria() along with buildElementsQuery() raw html gets displayed by the template
ThreadText: # When using getCriteria() along with buildElementsQuery() raw html gets displayed by the template
  
  (Asked by: username_0 on 2015-03-03)
  
  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 `<p>` and in the source of the page it is `&lt;p&gt;`. The `<p>` 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()->elements->getCriteria(ElementType::Entry);
      $criteria->section = 'library';
      $criteria->limit = 10;
  
      return ($criteria->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()->elements->getCriteria(ElementType::Entry);
      $criteria->section = 'library';
      $criteria->limit = 10;
  
      $query = craft()->elements->buildElementsQuery($criteria);
  
      return ($query->queryAll());
  
  }
  
  ```
  
  In my template:
  
  ```
  {% set my_library = craft.accd.my_library() %}
  
  {% for entry in my_library %} 
  
      {{ entry.title }}
      {{ entry.field_body}}
  
  {% endfor %}
  
  ```
  
  **Tags:** plugin-development, templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-03-03. Score: 7 | Accepted answer
  
  `$query->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()->elements->buildElementsQuery($criteria);
  
  // modify the query here
  
  $results = $query->queryAll();
  
  return EntryModel::populateModels($results);
  
  ```
  
  
  ---
  
  