Reputation: 1553
I'm actually using the Tools class in Prestashop 1.5 that allows me to display error messages to the front-end:
$this->errors[] = Tools::displayError( 'Fatal error!' );
Is there any function to display success messages the same way?
It seems that we can't use the l()
function inside of an extended ModuleFrontController()
Any advice would be greatly appreciated.
Upvotes: 2
Views: 9935
Reputation: 1
It is works for me in PrestaShop 1.7
$this->errors[] = "Error message!";
$this->success[] = "Success message!";
Upvotes: 0
Reputation: 14762
For success messages you can use:
$output = null;
$output .= $this->displayConfirmation('<message goes here!>');
For error messages you can use:
$output = null;
$output .= $this->displayError('<message goes here!>');
an in the end:
return $output;
or something like:
return $output.$this->displayForm();
Upvotes: 1
Reputation: 5202
The way you are displaying errors / success messages like below :
{if isset($success)}
<p class="success">{$success}</p>
{/if}
is good option. Please note that
Tools::displayError('Fatal error');
is not providing you any sort of styling for error messages, it just provides a way for translating errors at admin.
If you want your success messages should be translatable also then in your controller do it as followed :
$this->context->smarty->assign( 'success', 1 );
And then in your template file
{if isset($success)}
{l s='This is success message'}
{/if}
And if template file is in a module then use it as
{if isset($success)}
{l s='This is success message' mod='yourmodulename'}
{/if}
Hope this will help you.
Thank you
Upvotes: 3
Reputation: 1553
Found a solution but it's probably not the best:
Inside of my ModuleFrontController()
class:
$this->context->smarty->assign( 'success', 'Success!' );
At the top of my module's template file:
{if isset($success)}
<p class="success">{$success}</p>
{/if}
It displays "Success!" as intented.
Upvotes: 1