0

In my custom module I want to display a series of error messages for X, Y & Z. I have a single tag in the mod.[module_name].php file and I want to throw out an error if no id has been provided.

if ( !ee()->TMPL->fetch_param('contact_id') ) {
    ee()->output->fatal_error(lang('missing_contact_id'));
}

Now when I add the tag without the id the message appears but with the text 'missing_contact_id' rather than what is defined in my $lang language file.

Is there a way to output this on the front end?

It's worth noting that all my language strings are displaying correctly from the various functions in the mcp.[module_name].php file and the views that I have set up.

Thank you.

0

Just found an answer over at ExpressionEngine link

In case the link dies here is what is posted:

"If you want to display language messages in from end templates (for instance, in error messages) you must explicitly load the language file. Without loading it, the CP will render the language items just fine, but the front-end will not. So, in the hook function or constructor, load your language file like so:"

// if your lang file is named example_lang.php
public function __construct($settings = '') {
    $this->EE =& get_instance();
    $this->settings = $settings;
    $this->EE->lang->loadfile('example');
} 

or if you have a function for instance:

function cartthrob_pre_process() {
    $this->EE->lang->loadfile('example');
    $this->EE->output->show_user_error('general', lang('minimum_not_met') );
} 

Just a quick note, mine was called lang.module_name.php so I just used

ee()->lang->loadfile('module_name')

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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