I am writing my first EE plugin and have finally hit a roadblock. Here is how it looks

        class Thank_you {

        public function __construct()
            $this->EE = get_instance();

            $entries = $this->EE->db->from('channel_titles')->get();
public function contacts()

        $db2   = $this->EE->load->database('ext_db', TRUE);
        $query = $db2->select('FirstName, LastName, MealType')->order_by('id','DESC')->get('contact',10);

        $contacts = $query->result();

        return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $contacts);

So the goal here is to pass an array of contacts to the template and iterate from there. All that I get with


Is an output of {FirstName}. Where am I going wrong on this.


  • 1
    Just a quick comment, I notice you're loading your entire channel_titles table in the constructor. If that's not being used, then you definitely want to get rid of that, since it's adding an extra query to your database. Commented Feb 6, 2014 at 3:03

1 Answer 1


You need to loop through the query result and build an array containing your variables. Using the following code after your query should work.

if ($query->num_rows() == 0)
    return $this->EE->TMPL->no_results();

foreach ($query->result() as $row)
    $vars[] = array(
        'FirstName'     => $row->FirstName,
        'LastName'      => $row->LastName,
        'url_title'     => $row->MealType

return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $vars);
  • thx! Makes complete sense now. Need to build out the array, then pass.
    – SuperNinja
    Commented Feb 6, 2014 at 1:50
  • Hey no problem!
    – Dylan
    Commented Feb 6, 2014 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.