Skip to content

Instantly share code, notes, and snippets.

@ytake
Last active April 21, 2020 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytake/1a6f1d5312b552bc83ff to your computer and use it in GitHub Desktop.
Save ytake/1a6f1d5312b552bc83ff to your computer and use it in GitHub Desktop.
laravel-smarty registerFilter in Controller
<?php
namespace App\Controllers;
class HomeController extends BaseController
{
public function showWelcome()
{
\View::registerFilter('post', [$this, 'add_header_comment']);
// または
//$smarty = \View::getSmarty();
//$smarty->registerFilter('post', [$this, 'add_header_comment']);
return \View::make('hello');
}
/**
* @param $tpl_source
* @param $smarty
* @return string
*/
public function add_header_comment($tpl_source, $smarty)
{
return "<?php echo \"<!-- Created by Smarty! -->\n\"; ?>\n".$tpl_source;
}
}
@be3max
Copy link

be3max commented Apr 21, 2020

Its an error - Method Illuminate\View\Factory::getSmarty does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment