$custom_fields is not available in invoice templates and email template


Hi IP,

I can’t use $custom_fields inside the invoice template as it is not available.
I had tried print_r($custom_fields); it return variable not defined.

Also custom fields are not available in email templates. Although I use the dropdown selection to select the custom fields, something like {{{ip_cf_#}}}, the received email only show empty.

Some invoice variables are not available such as {{{invoice_status}}}, it give empty value.

I upgrade from 1.4.10 to 1.5.0 recently.

Please assist. Thanks

Custom field not showing in emails
Custom field code is not translated in email template

I experienced same thing, it works only on generated PDF file, any solution yet?


Then please upgrade to 1.5.2 or wait a few days until 1.5.3 get’s released. $custom_fields is available for all PDF files and custom fields are also avilable in email templates in all of my testing setups.

PO number field required in Invoice

I’m also having the same issue with the version 1.5.2. It works in the pdf but not in the email template (blank on emails). tags comes as {{{ip_cf_3}}}.


wish the $custom_fields also available in InvoicePlane_Web.php too.


In my setup the custom fields are also only working in PDF - not in email.

IP 1.5.2


I’m getting a PHP error in guest view… I think that $custom_fields is not available there.
Is it possibile to implement that in 1.5.3?

Here’s the error:

A PHP Error was encountered
Message: Undefined variable: custom_fields
Filename: public/mytemplate.php


Hi Kovah,
just installed 1.5.3 but custom fields inside email templates still not working, theres just a blank.


Same with me. Custom fields in e-mail template are not translated in invoice e-mails.


In my case (public view template) the problem was that I was using and old template from the v1.4.x.


Hi Foolab, are we talking about the same templates? I mean the invoice template that i created under Settings > Email Templates. Allthough I created a new template with version 1.5.3 it has the same issue as in 1.5.2. When I insert a custom field in this template ( {{{ip_cf_9}}} ) this field is not translated in the e-mail that is sent to the customer.


I was talking about public view templates only.


Hi everyone,

On my side, I still have the bug on email template and custom fields with version 1.5.3.
To correct it, I have just changed in the file Mdl_custom_fields.php the line 211 from

->where($cf_model_name . ‘_id’, $model_id)


->where($cf_table . ‘_id’, $model_id)

Hope it will fix the problem on your side too.


Hi OlivierMa,

Thanks for your reply.
For me it did not work. However when i compare the line in the code to what you published, I see that some underscores are missing(???)
Because I got a php error I changed the line so I did not get the php error but also not the custom field translated.

$value = $this->$custom_field_model
        ->where($cf_table . '_fieldid', $field_id)
       /* ->where($cf_model_name . '_id', $model_id) */
		->where($cf_table . '_id', $model_id)

Is this how it should work?


Yes this is what I wanted to write…

Does it work for you too ?


I tried it in my testenvironment (running version 1.52) but there it does not work. Can’t test it in my production environment right now. Could you send an exact copy of the lines 209 - 212 that worked for you because maybe i made a typo somewhere…


Hi Benny,

Actually, the code is not correct. I’m working on it right now.

EDIT : Could you please confirm that the following code works for you too ?

File application\modules\custom_fields\models\Mdl_custom_fields.php

public function get_value_for_field($field_id, $custom_field_model, $object)
    $this->load->model('custom_fields/' . $custom_field_model);

    $cf_table = str_replace('mdl_', '', $custom_field_model);
    $cf_model_name = str_replace('_custom', '', $cf_table);

    $value = $this->$custom_field_model
        ->where($cf_table . '_fieldid', $field_id)
        ->where($cf_model_name . '_id', $object->{$cf_model_name . '_id'})

    $value_key = $cf_table . '_fieldvalue';

    if (!isset($value[0]->$value_key)) {
        return '';

    return $value[0]->$value_key;

File application\helpers\template_helper.php
Function function parse_template($object, $body, $model_id)

// Check if it's a custom field
if (preg_match('/ip_cf_([0-9].*)/', $var, $cf_id)) {
	// Get the custom field
	$CI =& get_instance();
	$cf = $CI->mdl_custom_fields->get_by_id($cf_id[1]);

	if ($cf) {
		// Get the values for the custom field
		$cf_model = str_replace('ip_', 'mdl_', $cf->custom_field_table);
		$replace = $CI->mdl_custom_fields
			->get_value_for_field($cf_id[1], $cf_model, $object);
	} else {
		$replace = '';
} else {
	$replace = isset($object->{$var}) ? $object->{$var} : $var;


Hi OlivierMa, This looks great. I did a quick test in my v1.52 testenvironment with the customer field translation in the e-mail body and it works like a charm. Great job! I do not know if you are one of the developers but otherwise i hope this fix will be picked up by the development team.


The fix will be available in the next release.


Hello, I just tested the code you sent. I’m trying to add a custom field of single select to my email template, in order to make the distinction between “Dear Mrs” or “Dear Sir”. Unfortunately the custom field translates into its key rather than its value, so I see “Dear 1” or “Dear 2”.
Thanks a lot