Skip to content

Instantly share code, notes, and snippets.

@ytake
Created August 25, 2014 09: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/e8c834e88473ea3f10e7 to your computer and use it in GitHub Desktop.
Save ytake/e8c834e88473ea3f10e7 to your computer and use it in GitHub Desktop.
laravel-smarty registerFilter in ServiceProvider
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ApplicationServiceProvider extends ServiceProvider
{
public function boot()
{
$this->registerFilters();
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
}
public function registerFilters()
{
$smarty = $this->app['view']->getSmarty();
$smarty->registerFilter('post', [$this, 'add_header_comment']);
}
/**
* @param $tpl_source
* @param $smarty
* @return string
*/
public function add_header_comment($tpl_source, $smarty)
{
return "<?php echo \"<!-- Created by Smarty From ServiceProvider! -->\n\"; ?>\n".$tpl_source;
}
}
@Alokkaa
Copy link

Alokkaa commented Jan 16, 2019

It's get that error "Method Illuminate\View\Factory::getSmarty does not exist."

@yogeshGroony
Copy link

Same error,
Call to undefined method Illuminate\View\Factory::getSmarty()

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