ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
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. – Jeremy Gimbel Feb 6 '14 at 3:03
up vote 3 down vote accepted

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);
share|improve this answer
thx! Makes complete sense now. Need to build out the array, then pass. – Bungdaddy Feb 6 '14 at 1:50
Hey no problem! – Dylan Feb 6 '14 at 2:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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