How to create a custom macro in laravel 4

流过昼夜 提交于 2019-12-13 21:05:28

问题


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">&times;</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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!