ytake / Laravel.Smarty

smarty template engine for laravel
MIT License
84 stars 24 forks source link

Own plugin #57

Closed martinpesava closed 6 years ago

martinpesava commented 6 years ago

Hello, is it possible and how to write my own plugin, which won't be in the default smarty plugin directory inside vendor folder, but samewhere inside app folder? Thanks

ytake commented 6 years ago

By default 'plugins_paths'

    'plugins_paths'                       => [
        base_path() . '/resources/smarty/plugins',
    ],

https://github.com/ytake/Laravel.Smarty/blob/master/src/config/ytake-laravel-smarty.php#L56

or ServiceProviders example) register filter

<?php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ApplicationServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $this->registerFilters();
    }

    public function registerFilters(): void
    {
        $smarty = $this->app['view']->getSmarty();
        $smarty->registerFilter('post', [$this, 'add_header_comment']);
    }

    public function add_header_comment($tpl_source, $smarty)
    {
        return "<?php echo \"<!-- Created by Smarty From ServiceProvider! -->\n\"; ?>\n".$tpl_source;
    }
} 
martinpesava commented 6 years ago

Thanks, it worked.