Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

Alokkaa commented Jan 16, 2019

It's get that 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
You can’t perform that action at this time.