I'm trying to create my own custom field type, however, when I go to load the view, the var's within my display_field function, are Undefined. All I'm trying to do, is Load a view file, then in the view, loop through and array.


function display_field($data)
        $entry_id = $this->EE->input->get_post('entry_id');
        $query = $this->EE->db->query("SELECT * FROM exp_channel_images WHERE entry_id = '$entry_id'");

        $channelImages = array();

        if ($query->num_rows() > 0)
            foreach($query->result_array() as $row)
               array_push($channelImages, $row);

        return $this->EE->load->view('index', $channelImages, TRUE);

Then, my view file is called index.php, and is located under:


2 Answers 2


First, for new entries the get_post(entry_id) probably isn't set (check and verify it before running your query). Second, the view loader extracts the vars array passed to it, and your array doesn't have keys. instead of passing $channelImages array, try passing it inside an array, something like array('chanimg' => $chanimg)

See example below, and the part "adding dynamic data to the view"

$data = array(
  'chanimg' => array()

$entry_id = $this->EE->input->get_post('entry_id');
if ($entry_id > 0){
    // query
    // $data['chanimg'][] = $row;

return $this->EE->load->view('index', $data, TRUE);
  • Thank you, that was it. Now I simply reference "$chainimg" in the view, and my data is there!
    – Whnunlife
    Commented Apr 10, 2013 at 14:45

The display_field function of field type will not load view file so you need to return the data / content which you would like to show at edit or publish forms and SAEF.


function display_field($data){
other code

return "<div>SOME DATA or VARIABLES</div>";

  • While true that you need to return data/content from the display_field method for the publish screen. It is possible to use a custom view (say a whole table or a map with javascript) and fetch that view with the second parameter of load view set to true (return as string) and pass that data along from display field.
    – GDmac
    Commented Apr 15, 2013 at 21:17

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.