问题
Good Day how can I use a custom macro in laravel 4?
here is my custom macro
<?php
HTML::macro('flash', function()
{
$message_status = Session::get('status');
$message = Session::get('message');
$type = Session::get('type');
return ($message_status && $message) ? '<div class="alert alert-'.$message_status.'"><a class="close" data-dismiss="alert" href="#" aria-hidden="true">×</a><p>'.$message.' '.$type.'</p></div>':'';
});
?>
I created a new file inside app
folder named macros.php
and paste the above code there, also added require app_path().'/macros.php';
at the bottom of app/start/global.php
, but when I try to access it on my view using <?php echo HTML::flash(); ?>
I got this
syntax error, unexpected 'HTML' (T_STRING), expecting function (T_FUNCTION)
also this is my way of passing values from my controller:
return Redirect::action('SuppliersController@show',$supplierId)
->with('status','success')
->with('message', Lang::get('alerts.messages.successUpdate'))
->with('type', Lang::get('alerts.transactions.po'));
Here is my view: view

can anyone help me figure out whats going on here please. This is my first time on using custom macro.
Thank you very much
-Melvn
来源:https://stackoverflow.com/questions/20529413/how-to-create-a-custom-macro-in-laravel-4