1. Go to this page and download the library: Download miko/laravel-latte library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Latte\Essential\TranslatorExtension;
use Miko\LaravelLatte\Runtime\Translator;
public function boot(): void
{
$latte = $this->app->get(\Latte\Engine::class);
$latte->addExtension(new TranslatorExtension([Translator::class, 'translate']));
}
namespace App\View\Components;
use Illuminate\View\View;
use Miko\LaravelLatte\IComponent;
class Alert implements IComponent
{
private array $params = [];
/**
* Get some services from service container
*/
public function __construct(private SomeService $someService)
{
}
/**
* Get variables from template
*/
public function init(...$params): void
{
$this->params = $params;
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|string
{
return view('components.alert', $this->params);
}
}
// app\Providers\LatteServiceProvider
namespace App\Providers;
use Latte\Engine as Latte;
class LatteServiceProvider extends \Miko\LaravelLatte\ServiceProvider
{
/**
* Override this method for custom setup
* @param \Latte\Engine $latte
* @return void
*/
protected function configure(Latte $latte): void
{
parent::configure($latte);
$latte->setSomething($this->config->get('latte.something'));
}
/**
* Override this method for a custom extension
* https://latte.nette.org/extending-latte
* @param \Latte\Engine $latte
* @return void
*/
protected function extensions(Latte $latte): void
{
parent::extensions($latte);
$latte->addFunction(...);
$latte->addFilter(...);
$latte->addExtension(...);
}
}