### listenToEvents(): void method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Declares the method that installs profiling into the environment. Called after Clockwork resolves to start recording template profiles. ```php public function listenToEvents(): void ``` -------------------------------- ### Manual wiring example Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelTemplatesCache.md Shows how to manually wire the filesystem and templates cache into the liquid.factory, as done in tests. Requires a LiquidCompiler instance and imports LaravelLiquidFileSystem and LaravelTemplatesCache. ```php use Keepsuit\LaravelLiquid\Support\LaravelLiquidFileSystem; use Keepsuit\LaravelLiquid\Support\LaravelTemplatesCache; $environment = app('liquid.factory') ->setFilesystem(new LaravelLiquidFileSystem($compiler)) ->setTemplatesCache(new LaravelTemplatesCache($compiler)) ->build(); ``` -------------------------------- ### Custom extension class example (ShopExtension) Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/configuration.md Consumer-side example of a custom extension that registers a tag and a filters provider. The class must extend Keepsuit\Liquid\Extensions\Extension and is resolved from the container, so it can use dependency injection. ```php listenToEvents(); ``` ``` -------------------------------- ### Install laravel-liquid via Composer Source: https://github.com/keepsuit/laravel-liquid/blob/main/README.md Install the package using Composer. Run this command in your project root to add keepsuit/laravel-liquid as a dependency. ```bash composer require keepsuit/laravel-liquid ``` -------------------------------- ### Basic call to LiquidEngine::get() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidEngine.md Resolves the liquid engine from the view engine resolver and calls get() with a view path and data array. Returns the rendered HTML string. ```php $engine = app('view.engine.resolver')->resolve('liquid'); $html = $engine->get(resource_path('views/home.liquid'), ['name' => 'World']); ``` -------------------------------- ### LiquidEngine::get() method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidEngine.md Signature of the get() method that renders a view file. Returns ?string, always a string in practice, and throws ViewException on LiquidException. ```php public function get($path, array $data = []): ?string ``` -------------------------------- ### Basic Liquid parse and render example Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Shows how to parse a view named 'newsletter' and render it with a new render context containing user data. Uses the Liquid facade. ```php use Keepsuit\LaravelLiquid\Facades\Liquid; $template = Liquid::parse('newsletter'); $html = $template->render(Liquid::environment()->newRenderContext(data: ['user' => $user])); ``` -------------------------------- ### listenToEvents() implementation Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Installs a new Profiler and adds a ProfilerExtension to the liquid environment. After this, every template parsed/rendered through the shared environment records profiles. ```php $this->profiler = new Profiler; $this->liquidEnvironment->addExtension(new ProfilerExtension($this->profiler)); ``` -------------------------------- ### ViewException wrapping logic Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Throws a ViewException with a message including the view path. The previous exception is mapped: SyntaxException gets a new instance with filename and line, InternalException uses its previous, others use the original. ```php throw new ViewException( message: sprintf('%s (View: %s)', $e->getMessage(), $path), previous: match (true) { $e instanceof SyntaxException => new SyntaxException( message: $e->getMessage(), filename: $path, line: $e->lineNumber, ), $e instanceof InternalException => $e->getPrevious(), default => $e, }, ); ``` -------------------------------- ### Call environment() to create a render context and render a template Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Use the Liquid facade's environment() method to access the underlying Keepsuit\Liquid\Environment instance, which exposes low-level operations like newRenderContext() and parseTemplate(). The example creates a render context with data and renders the 'home' template. ```php use Keepsuit\LaravelLiquid\Facades\Liquid; $context = Liquid::environment()->newRenderContext(data: ['name' => 'World']); echo Liquid::parse('home')->render($context); ``` -------------------------------- ### Install Clockwork via Composer Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Installs the optional clockwork/clockwork package. No application code is required; the integration activates automatically when this package is present. ```bash composer require itsgoingd/clockwork ``` -------------------------------- ### readTemplateFile implementation Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidFileSystem.md Returns the template source by resolving the path via getPathFromTemplateName() and reading the file with getFiles()->get(). ```php return $this->compiler->getFiles()->get($this->compiler->getPathFromTemplateName($templateName)); ``` -------------------------------- ### Full custom configuration for config/liquid.php Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/configuration.md Example configuration file with strict_variables and strict_filters enabled and a custom extension list. The extensions array must contain class strings that are subclasses of Extension; entries failing the filter are skipped. ```php true, 'strict_filters' => true, 'extensions' => [ \Keepsuit\LaravelLiquid\LaravelLiquidExtension::class, \App\Liquid\ShopExtension::class, ], ]; ``` -------------------------------- ### get($path, array $data = []): ?string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidEngine.md Renders a Liquid template file at the given path with the provided data. This method is called by Laravel's view engine resolver when rendering a .liquid view, and it delegates to the LiquidCompiler to produce the final HTML output. ```APIDOC ## get($path, array $data = []): ?string ### Description Renders a Liquid template file at the given path with the provided data. This method is called by Laravel's view engine resolver when rendering a .liquid view, and it delegates to the LiquidCompiler to produce the final HTML output. ### Method GET (view rendering) ### Endpoint N/A (PHP method) ### Parameters #### Path Parameters - **$path** (string) - Required - Absolute path of the view file to render. #### Query Parameters - **$data** (array) - Optional - Data passed to the render context. Defaults to `[]`. ### Request Example ```php $engine = app('view.engine.resolver')->resolve('liquid'); $html = $engine->get(resource_path('views/home.liquid'), ['name' => 'World']); ``` ### Response #### Success Response (200) - **string** - The rendered template output (always a string in practice; `null` only if the compiler returned `null`, which it does not). #### Response Example ```html ``` ### Errors - **Illuminate\View\ViewException** - Wraps any `Keepsuit\Liquid\Exceptions\LiquidException` raised during rendering. ``` -------------------------------- ### registerClockwork() method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidServiceProvider.md Protected method that conditionally integrates Clockwork when the Clockwork class is installed. Registers the 'clockwork.liquid' singleton and adds a data source to the Clockwork instance. ```php protected function registerClockwork(): void ``` -------------------------------- ### get(string $name): ?Template Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelTemplatesCache.md Retrieves a compiled template from the cache by name. Returns null if the template is missing or expired. ```APIDOC ## get(string $name): ?Template ### Description Retrieves a compiled template from the cache by name. Returns null if the template is missing or expired. ### Method GET ### Parameters - **$name** (string) - Required - Template/view name (e.g. `home`). ### Return ?Keepsuit\Liquid\Template - The cached compiled template, or null when missing or expired. ### Example ```php $template = $cache->get('home'); ``` ``` -------------------------------- ### Manual usage outside the provider Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Creates a LiquidDataSource with a custom environment and starts profiling. Use this when building a custom environment instead of relying on the automatic provider wiring. ```php use Keepsuit\LaravelLiquid\Support\Clockwork\LiquidDataSource; $source = new LiquidDataSource($environment); $source->listenToEvents(); ``` -------------------------------- ### Service provider wiring for clockwork.liquid Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Registers the clockwork.liquid singleton and hooks into Clockwork resolution. addDataSource() is called before listenToEvents() to ensure profiling starts after Clockwork resolves. ```php $this->app->singleton('clockwork.liquid', function (Application $app) { return new LiquidDataSource($app->make('liquid.environment')); }); $this->callAfterResolving('clockwork', function (Clockwork $clockwork) { $dataSource = $this->app->make('clockwork.liquid'); assert($dataSource instanceof LiquidDataSource); $clockwork->addDataSource($dataSource); $dataSource->listenToEvents(); }); ``` -------------------------------- ### Instantiation in LiquidServiceProvider::packageRegistered() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidFileSystem.md Shows how the service provider creates the filesystem instance when building liquid.factory, using the 'liquid.compiler' container binding. ```php $filesystem = new LaravelLiquidFileSystem( compiler: $app->make('liquid.compiler') ); ``` -------------------------------- ### Basic call to Liquid::render() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Renders the 'home' view with a 'name' variable and echoes the resulting HtmlString. The output is 'Hello World' from home.liquid. ```php use Keepsuit\LaravelLiquid\Facades\Liquid; $html = Liquid::render('home', ['name' => 'World']); echo $html; // HtmlString – echoes "Hello World" (from home.liquid) ``` -------------------------------- ### Publish and configure Liquid config Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidServiceProvider.md Publishes the config file and shows a sample config/liquid.php with strict_variables and custom extensions. ```bash php artisan vendor:publish --provider="Keepsuit\LaravelLiquid\LiquidServiceProvider" ``` ```php // config/liquid.php return [ 'strict_variables' => true, 'extensions' => [ \Keepsuit\LaravelLiquid\LaravelLiquidExtension::class, \App\Liquid\MyExtension::class, // any Keepsuit\Liquid\Extensions\Extension subclass ], ]; ``` -------------------------------- ### configurePackage method Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidServiceProvider.md Registers the package under the name 'laravel-liquid', publishes the config file 'config/liquid.php', and registers the 'liquid:cache' command. ```php public function configurePackage(Package $package): void { $package ->name('laravel-liquid') ->hasConfigFile() ->hasCommand(LiquidCacheCommand::class); } ``` -------------------------------- ### packageBooted method Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidServiceProvider.md Hooks 'liquid:cache' into Laravel's 'php artisan optimize' command with cache key 'liquid', so 'optimize:clear' removes the artifacts. ```php public function packageBooted(): void { $this->optimizes(optimize: 'liquid:cache', key: 'liquid'); } ``` -------------------------------- ### LiquidEngine constructor Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidEngine.md Constructor for the LiquidEngine class. Accepts a LiquidCompiler instance and a Filesystem instance, forwarding the filesystem to the parent PhpEngine constructor. Normally instantiated by the service provider, not manually. ```php public function __construct( protected LiquidCompiler $compiler, Filesystem $files ) { parent::__construct($files); } ``` -------------------------------- ### get method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelTemplatesCache.md Retrieves a cached compiled template by name, returning null if missing or expired. On first lookup per name, it checks isExpired() and removes the entry if expired; subsequent lookups skip the check. ```php public function get(string $name): ?Template ``` -------------------------------- ### Basic render call using liquid.compiler Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Retrieves the Liquid compiler from the container and renders a view file, passing an array of data. Returns the fully rendered template output. ```php $compiler = app('liquid.compiler'); $html = $compiler->render(resource_path('views/home.liquid'), ['name' => 'World']); ``` -------------------------------- ### getFiles(): Filesystem method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Returns the inherited Filesystem instance used by LaravelLiquidFileSystem and LaravelTemplatesCache. ```php public function getFiles(): Filesystem ``` -------------------------------- ### EnvTag render() method Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/EnvTag.md Renders the body based on environment match. ```php public function render(RenderContext $context): string ``` -------------------------------- ### Add extension programmatically to environment factory Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidExtension.md Build an environment and add the extension when you already hold a factory instance. EnvironmentFactory::new() is the canonical way to build an environment. ```php use Keepsuit\LaravelLiquid\LaravelLiquidExtension; $environment = app('liquid.factory') ->build() ->addExtension(new LaravelLiquidExtension); ``` -------------------------------- ### Run liquid:cache artisan command Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCacheCommand.md Executes the command to pre-compile all discoverable Liquid templates into PHP artifacts. This is the ahead-of-time compilation pass used on deployment. ```bash php artisan liquid:cache ``` -------------------------------- ### Constructor Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelTemplatesCache.md Initializes the LaravelTemplatesCache with a LiquidCompiler instance. The compiler provides cache path and file operations. ```APIDOC ## Constructor ### Description Initializes the LaravelTemplatesCache with a LiquidCompiler instance. ### Method Constructor ### Parameters - **$compiler** (Keepsuit\LaravelLiquid\LiquidCompiler) - Required - Provides getCachePath(), isExpired(), getPathFromTemplateName(), getCompiledPath(), and getFiles(). ### Example ```php new LaravelTemplatesCache($compiler) ``` ``` -------------------------------- ### Instantiate LiquidCompiler in service provider Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Creates a new LiquidCompiler instance with Laravel's filesystem, compiled view cache path, optional base path for relative hashing, and caching flag. Used in the service provider to register the compiler. ```php new LiquidCompiler( files: $app['files'], cachePath: $app['config']['view.compiled'], basePath: $app['config']->get('view.relative_hash', false) ? $app->basePath() : '', shouldCache: (bool) $app['config']->get('view.cache', true), ); ``` -------------------------------- ### Manual usage with custom environment factory Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidFileSystem.md Shows manual construction of LaravelLiquidFileSystem and LaravelTemplatesCache to build a custom environment, then reading a partial template. This is only needed when not using the automatic service provider wiring. ```php use Keepsuit\LaravelLiquid\Support\LaravelLiquidFileSystem; use Keepsuit\LaravelLiquid\Support\LaravelTemplatesCache; $compiler = app('liquid.compiler'); $fs = new LaravelLiquidFileSystem($compiler); $environment = app('liquid.factory') ->setFilesystem($fs) ->setTemplatesCache(new LaravelTemplatesCache($compiler)) ->build(); $source = $fs->readTemplateFile('partials.header'); ``` -------------------------------- ### Template usage with multiple environments and else Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/EnvTag.md Liquid template using {% env %} with multiple environments and an else branch. ```liquid {% env 'production', 'staging' %} we are on a live environment {% else %} we are not on a live environment {% endenv %} ``` -------------------------------- ### Resolve Liquid services from container Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidServiceProvider.md Shows how to resolve the environment, factory, and compiler from the Laravel container using the registered bindings. ```php $environment = app('liquid.environment'); // Keepsuit\Liquid\Environment $factory = app('liquid.factory'); // Keepsuit\Liquid\EnvironmentFactory $compiler = app('liquid.compiler'); // Keepsuit\LaravelLiquid\LiquidCompiler ``` -------------------------------- ### getViewFinder(): FileViewFinder method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Resolves the view factory's finder and asserts it is a FileViewFinder. ```php public function getViewFinder(): FileViewFinder ``` -------------------------------- ### Use Facade from a Service Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md Usage of the facade from a service class. Calls Liquid::render() and converts the result to a plain string with toHtml(). ```php use Liquid; final class NewsletterMailer { public function body(array $data): string { return Liquid::render('emails.newsletter', $data)->toHtml(); } } ``` -------------------------------- ### Constructor Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Creates a new LiquidDataSource instance with the shared Liquid environment to be profiled. ```APIDOC ## Constructor ### Description Creates a new LiquidDataSource instance with the shared Liquid environment to be profiled. ### Method Constructor ### Signature ```php public function __construct(protected Environment $liquidEnvironment) {} ``` ### Parameters - `$liquidEnvironment` (Keepsuit\Liquid\Environment) - Required - The shared `liquid.environment` singleton to be profiled. ### Usage Example ```php $source = new LiquidDataSource($environment); ``` ``` -------------------------------- ### Run test suite with composer test Source: https://github.com/keepsuit/laravel-liquid/blob/main/README.md Run the test suite with compiled templates using the `composer test` command. ```bash composer test ``` -------------------------------- ### getEnvironment(): Environment method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Returns the shared Keepsuit\Liquid\Environment singleton resolved from the container. ```php protected function getEnvironment(): Environment ``` -------------------------------- ### handle method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCacheCommand.md The handle method signature for the command. It accepts an injected Illuminate\View\Factory used to discover which extensions are mapped to the 'liquid' engine. Returns self::SUCCESS (0) after reporting the cached template count via $this->components->info(...). ```php public function handle(Factory $view): int ``` -------------------------------- ### environment Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md Returns the underlying Liquid environment. This method is a static proxy to the underlying Liquid instance. ```APIDOC ## environment ### Description Returns the underlying Liquid environment. ### Method `environment` ### Signature `environment(): \Keepsuit\Liquid\Environment` ### Parameters None. ### Return Value - **\Keepsuit\Liquid\Environment** - The underlying Liquid environment. ### Example ```php $env = Liquid::environment(); ``` ``` -------------------------------- ### Liquid Facade @method Docblock Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md The facade's PHPdoc declares forwarded methods that proxy to Keepsuit\LaravelLiquid\Liquid: parse, render, stream, and environment. ```php /** * @method static Template parse(string $view) * @method static HtmlString render(string $view, array $data = []) * @method static \Generator stream(string $view, array $data = []) * @method static Environment environment() */ ``` -------------------------------- ### Render a Liquid view in a Laravel controller Source: https://github.com/keepsuit/laravel-liquid/blob/main/README.md Create a liquid template file in resources/views (e.g., home.liquid) and render it with Laravel's view helper. The view name omits the .liquid extension. ```php class HomeController extends Controller { public function index() { return view('home'); } } ``` -------------------------------- ### Constructor: LiquidDataSource __construct Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Creates a new LiquidDataSource instance wrapping the shared liquid.environment singleton. The environment is profiled for Clockwork timeline events. ```php public function __construct(protected Environment $liquidEnvironment) {} ``` -------------------------------- ### Class declaration with AsCommand attribute and signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCacheCommand.md Declares the Artisan command class registered as 'liquid:cache'. The signature has no arguments or options, and the description is "Compile all of the application's Liquid templates". The handle method receives an injected Illuminate\View\Factory and returns an int (self::SUCCESS). ```php #[AsCommand(name: 'liquid:cache')] class LiquidCacheCommand extends Command { protected $signature = 'liquid:cache'; protected $description = "Compile all of the application's Liquid templates"; public function handle(Factory $view): int ``` -------------------------------- ### Basic call to Liquid::stream() with response()->stream() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Streams the 'home' view in chunks within a Laravel response, echoing each chunk to flush progressively without buffering the whole template. ```php use Keepsuit\LaravelLiquid\Facades\Liquid; return response()->stream(function () { foreach (Liquid::stream('home', ['name' => 'World']) as $chunk) { echo $chunk; } }); ``` -------------------------------- ### Typical usage via Laravel view factory Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidEngine.md Uses the standard Laravel view() helper to render a Liquid template. The engine is used implicitly through the view factory. ```php Route::get('/', fn () => view('home', ['name' => 'World'])); ``` -------------------------------- ### render(string $path, array $data): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Renders a Liquid template from an absolute filesystem path with the given view data. Returns the fully rendered template output as a string. ```APIDOC ## render(string $path, array $data): string ### Description Renders a Liquid template from an absolute filesystem path with the given view data. Returns the fully rendered template output as a string. ### Method render ### Parameters #### Path Parameters - **$path** (string) - Required - Absolute filesystem path of the view to render. #### Request Body - **$data** (array) - Required - View data passed to `newRenderContext(data: $data)`. ### Return - **string** - Fully rendered template output. ### Throws - **Illuminate\View\ViewException** - On any `Keepsuit\Liquid\Exceptions\LiquidException`. ### Request Example ```php $compiler = app('liquid.compiler'); $html = $compiler->render(resource_path('views/home.liquid'), ['name' => 'World']); ``` ``` -------------------------------- ### ViteTag pushEntrypointsToContext() method Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/ViteTag.md Pushes metadata entries for each entrypoint to the parse context outputs under 'vite_entrypoints'. ```php protected function pushEntrypointsToContext(ParseContext $parseContext): void { $parseContext->getOutputs()->push( 'vite_entrypoints', ...array_map(fn (string $entrypoint) => [ 'entrypoint' => $entrypoint, ...$this->attributes, ], $this->entrypoints) ); } ``` -------------------------------- ### url(string $name, string|int ...$parameters): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Filters/UrlFilters.md Generates a URL using the url() helper, with optional extra path segments. ```APIDOC ## url(string $name, string|int ...$parameters): string ### Description Generates a URL using the url() helper, with optional extra path segments. ### Method url ### Parameters - **$name** (string) - Required - Path or route name. - **...$parameters** (string|int) - Optional - Extra path segments (variadic). ### Return string - URL via the url() helper. ### Example ```liquid {{ '/home' | url }} ``` ``` -------------------------------- ### packageRegistered() method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidServiceProvider.md Declares the packageRegistered() method that registers container bindings and the view engine extension. ```php public function packageRegistered(): void ``` -------------------------------- ### Constructor: LaravelLiquidFileSystem __construct Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidFileSystem.md Defines the constructor that accepts a LiquidCompiler instance, which provides getPathFromTemplateName() and getFiles(). The compiler is required and stored as a protected property. ```php public function __construct( protected LiquidCompiler $compiler, ) {} ``` -------------------------------- ### Publish config file with artisan vendor:publish Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/configuration.md Run this command to publish the package configuration file to config/liquid.php. The provider flag is Keepsuit\LaravelLiquid\LiquidServiceProvider. ```bash php artisan vendor:publish --provider="Keepsuit\LaravelLiquid\LiquidServiceProvider" ``` -------------------------------- ### Build liquid.factory environment with filesystem, cache, and strictness flags Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/configuration.md Constructs the `liquid.factory` singleton in `LiquidServiceProvider::packageRegistered()`. Uses the application filesystem and templates cache, rethrows errors when debug mode is enabled, and reads `liquid.strict_variables` and `liquid.strict_filters` config values (both default to `false`). ```php $environment = EnvironmentFactory::new() ->setFilesystem($filesystem) ->setTemplatesCache($templatesCache) ->setRethrowErrors($app->hasDebugModeEnabled()) ->setStrictVariables(config()->boolean('liquid.strict_variables', false)) ->setStrictFilters(config()->boolean('liquid.strict_filters', false)); ``` -------------------------------- ### Error handling for readTemplateFile Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidFileSystem.md Shows catching FileNotFoundException when reading a missing template. The exception propagates from the view finder or filesystem when the view name is not registered or the file is missing. ```php try { $source = $fs->readTemplateFile('missing.partial'); } catch (\Illuminate\Contracts\Filesystem\FileNotFoundException $e) { // view name not registered, or file missing at the resolved path } ``` -------------------------------- ### environment(): Environment Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Returns the underlying Liquid environment instance, exposing low-level operations such as newRenderContext() and parseTemplate(). This method is called directly on the Liquid facade. ```APIDOC ## environment(): Environment ### Description Returns the underlying Liquid environment instance, exposing low-level operations such as `newRenderContext()` and `parseTemplate()`. ### Method `environment()` ### Endpoint `Liquid::environment()` ### Parameters None. ### Return - **Type**: `Keepsuit\Liquid\Environment` - **Description**: The underlying environment instance. ### Example ```php use Keepsuit\LaravelLiquid\Facades\Liquid; $context = Liquid::environment()->newRenderContext(data: ['name' => 'World']); echo Liquid::parse('home')->render($context); ``` ``` -------------------------------- ### Constructor for LaravelTemplatesCache Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelTemplatesCache.md Initializes the cache with a LiquidCompiler instance, passing the compiler's cache path to the parent class. The compiler provides methods like getCachePath(), isExpired(), getPathFromTemplateName(), getCompiledPath(), and getFiles(). ```php public function __construct( protected LiquidCompiler $compiler, ) { parent::__construct($compiler->getCachePath()); } ``` -------------------------------- ### Run as part of optimize Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCacheCommand.md The liquid:cache command also runs as part of the standard optimize command, which pre-compiles application caches. ```bash php artisan optimize ``` -------------------------------- ### render Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md Parses and renders a view to an HTML-safe string. This method is a static proxy to the underlying Liquid instance and returns an HtmlString. ```APIDOC ## render ### Description Parses and renders a view to an HTML-safe string. ### Method `render` ### Signature `render(string $view, array $data = []): \Illuminate\Support\HtmlString` ### Parameters - **$view** (string) - Required - The view name to render. - **$data** (array) - Optional - Data to pass to the view. ### Return Value - **\Illuminate\Support\HtmlString** - The rendered HTML-safe string. ### Example ```php $html = Liquid::render('home', ['name' => 'World']); ``` ``` -------------------------------- ### render method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Declares the render method that renders a Liquid template from an absolute path with view data. Throws Illuminate\View\ViewException on any Keepsuit\Liquid\Exceptions\LiquidException. ```php /** * @throws ViewException */ public function render(string $path, array $data): string ``` -------------------------------- ### stream() method signature with docblock Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Signature for the stream method that yields rendered output in chunks. Errors are thrown while iterating, after earlier chunks may already have been sent, so partial responses cannot be rolled back. ```php /** * Errors are thrown while iterating, after earlier chunks may already have been sent. * * @return \Generator */ public function stream(string $view, array $data = []): \Generator ``` -------------------------------- ### Advanced manual chunk collection with Liquid::stream() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Collects streamed chunks into a buffer and flushes to disk incrementally when the buffer exceeds 4096 bytes, using FILE_APPEND. Useful for large reports. ```php use Keepsuit\LaravelLiquid\Facades\Liquid; $buffer = ''; foreach (Liquid::stream('report', ['rows' => $rows]) as $chunk) { $buffer .= $chunk; if (strlen($buffer) > 4096) { // flush to disk incrementally file_put_contents($tmpPath, $buffer, FILE_APPEND); $buffer = ''; } } ``` -------------------------------- ### Liquid constructor with Environment dependency Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Constructor for the Liquid class that accepts a pre-built Keepsuit\Liquid\Environment. Normally invoked by the container; resolve via app(Liquid::class) or use the facade instead of manual instantiation. ```php public function __construct( protected Environment $environment ) {} ``` -------------------------------- ### parse(TagParseContext $context): static Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/ViteTag.md Parses the token stream for the Vite tag and records entrypoints on the parse context's outputs under the key 'vite_entrypoints'. ```APIDOC ## parse(TagParseContext $context): static ### Description Parses the token stream for the Vite tag and records entrypoints on the parse context's outputs under the key 'vite_entrypoints'. ### Method `parse` ### Parameters - **$context** (Keepsuit\Liquid\Parse\TagParseContext) - Required - Parse context. ### Return - **static** - The current instance. ### Example ```php $tag->parse($context); ``` ``` -------------------------------- ### Add extension via config/liquid.php Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidExtension.md Explicitly add the extension alongside your own extensions in the liquid.extensions config array. ```php // config/liquid.php return [ 'extensions' => [ \Keepsuit\LaravelLiquid\LaravelLiquidExtension::class, \App\Liquid\MyExtension::class, ], ]; ``` -------------------------------- ### asset(string $path): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Filters/UrlFilters.md Generates a full URL for an asset relative to the public directory, honoring ASSET_URL when set. ```APIDOC ## asset(string $path): string ### Description Generates a full URL for an asset relative to the public directory, honoring ASSET_URL when set. ### Method asset ### Parameters - **$path** (string) - Required - Asset path relative to the public directory. ### Return string - Full URL for the asset. ### Example ```liquid {{ 'app.js' | asset }} ``` ``` -------------------------------- ### Render a View in a Controller Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md Basic usage of the Liquid facade to render a view inside a controller. Uses the Liquid alias and returns the HTML-safe string from Liquid::render(). ```php 'World']); } } ``` -------------------------------- ### EnvTag compile() method Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/EnvTag.md Emits compiled PHP code for environment check. ```php public function compile(CompilerContext $context): void ``` -------------------------------- ### readTemplateFile method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidFileSystem.md Declares the readTemplateFile method that takes a template name (e.g., 'home', 'partials.footer') and returns the raw Liquid template source as a string. ```php public function readTemplateFile(string $templateName): string ``` -------------------------------- ### render(RenderContext $context): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/ViteTag.md Renders the HTML tags for the given Vite entrypoints, equivalent to Laravel's @vite directive. Supports custom build directory and hot file. ```APIDOC ## render(RenderContext $context): string ### Description Renders the HTML tags for the given Vite entrypoints, equivalent to Laravel's @vite directive. Supports custom build directory and hot file. ### Method `render` ### Parameters - **$context** (Keepsuit\Liquid\Render\RenderContext) - Required - Render context. ### Return - **string** - HTML tags for the entrypoints. ### Behavior 1. Resolves `Illuminate\Foundation\Vite` from the container and clones it. 2. If `directory` attribute is set, calls `$vite->useBuildDirectory($directory)`. 3. If `hot` attribute is set, calls `$vite->useHotFile($hot)`. 4. Calls `$vite->withEntryPoints($this->entrypoints)->toHtml()`. 5. Records each preloaded asset on the render context outputs as `vite_preloads` with keys `href`, `attributes`, `directory`, `hot`. ### Example ```liquid {% vite 'resources/css/app.css', 'resources/js/app.js' %} ``` ``` -------------------------------- ### parse Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md Parses a view into a Liquid template. This method is a static proxy to the underlying Liquid instance and returns a Template object. ```APIDOC ## parse ### Description Parses a view into a Liquid template. ### Method `parse` ### Signature `parse(string $view): \Keepsuit\Liquid\Template` ### Parameters - **$view** (string) - Required - The view name to parse. ### Return Value - **\Keepsuit\Liquid\Template** - The parsed template. ### Example ```php $template = Liquid::parse('home'); ``` ``` -------------------------------- ### render() method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Signature for the render method that parses and renders a Liquid view, returning an HtmlString. The $view parameter is required and $data defaults to an empty array. ```php public function render(string $view, array $data = []): HtmlString ``` -------------------------------- ### secureUrl(string $path): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Filters/UrlFilters.md Generates an HTTPS URL using the secure_url() helper. ```APIDOC ## secureUrl(string $path): string ### Description Generates an HTTPS URL using the secure_url() helper. ### Method secureUrl ### Parameters - **$path** (string) - Required - Path. ### Return string - HTTPS URL via the secure_url() helper. ### Example ```liquid {{ '/home' | secure_url }} ``` ``` -------------------------------- ### Stream a View with Response Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md Usage of the facade with the streamed response pattern. Iterates over Liquid::stream('report') chunks and echoes each chunk inside a response()->stream() callback. ```php use Liquid; Route::get('/report', function () { return response()->stream(function () { foreach (Liquid::stream('report') as $chunk) { echo $chunk; } }); }); ``` -------------------------------- ### EnvTag parse() method Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/EnvTag.md Parses environment names and else sub-tag. ```php public function parse(TagParseContext $context): static ``` -------------------------------- ### Basic call to LiquidEngine::forgetCompiled() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidEngine.md Resolves the liquid engine and calls forgetCompiled() to force re-parsing of the next Liquid::parse() or view() call. ```php $engine = app('view.engine.resolver')->resolve('liquid'); $engine->forgetCompiled(); // forces re-parse of the next Liquid::parse()/view() call ``` -------------------------------- ### Error handling for invalid view name in render() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Catches FileNotFoundException when rendering a non-existent view, with the message 'Template not found from path: ...'. Aborts with a 404 response. ```php use Illuminate\Contracts\Filesystem\FileNotFoundException; use Keepsuit\LaravelLiquid\Facades\Liquid; try { $html = Liquid::render('does-not-exist'); } catch (FileNotFoundException $e) { // "Template not found from path: ..." abort(404); } ``` -------------------------------- ### Generate URLs with asset, url, and route filters Source: https://github.com/keepsuit/laravel-liquid/blob/main/README.md Generate URLs using Laravel's URL helpers: `asset` and `secure_asset` for assets, `url` and `secure_url` for URLs, and `route` for named routes. ```liquid {{ 'app.js' | asset }} {{ 'app.js' | secure_asset }} {{ '/home' | url }} {{ '/home' | secure_url }} {{ 'home' | route }} ``` -------------------------------- ### dump() method implementation Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Filters/DebugFilters.md Captures Laravel's dump() output using output buffering and returns it as a string, suppressing the global side-effect. Returns '' when no output is captured. ```php public function dump(mixed $value): string { ob_start(); dump($this->mapValue($value)); $dump = ob_get_contents(); ob_end_clean(); if ($dump === false) { return ''; } return $dump; } ``` -------------------------------- ### resolve() implementation with profile merging Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidDataSource.md Returns the request untouched when no profiles are recorded. Otherwise dumps profiles via ProfilerClockworkDumper, merges the timeline into viewsData, and returns the request. ```php if ($this->profiler->getProfiles() === []) { return $request; } $timeline = (new ProfilerClockworkDumper)->dump($this->profiler); $request->viewsData = array_merge($request->viewsData, $timeline->finalize()); return $request; ``` -------------------------------- ### viteAsset(string $path, ?string $buildDirectory = null): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Filters/UrlFilters.md Resolves the URL of a versioned Vite asset, optionally specifying a custom build directory. ```APIDOC ## viteAsset(string $path, ?string $buildDirectory = null): string ### Description Resolves the URL of a versioned Vite asset, optionally specifying a custom build directory. ### Method viteAsset ### Parameters - **$path** (string) - Required - Path of a versioned Vite asset. - **$buildDirectory** (?string) - Optional - Custom build directory forwarded to Vite::asset(). Default: null. ### Return string - URL of the versioned asset. ### Example ```liquid {{ 'images/logo.svg' | vite_asset }} {{ 'images/logo.svg' | vite_asset: 'custom' }} ``` ``` -------------------------------- ### dump(Profiler $profiler): Timeline method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/ProfilerClockworkDumper.md Public method that converts a Profiler into a Clockwork Timeline. Only closed profiles are included; open/unfinished profiles are skipped via isClosed(). Event names follow the pattern liquid::Tag ({name}), liquid::Variable ({name}), or liquid::{name} for other types. ```php public function dump(Profiler $profiler): Timeline ``` -------------------------------- ### getCachePath(): string method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Returns the inherited cache path (the view.compiled directory). ```php public function getCachePath(): string ``` -------------------------------- ### Auth and guest tags Source: https://github.com/keepsuit/laravel-liquid/blob/main/README.md Custom Liquid tags equivalent to Laravel's @auth and @guest directives. Use {% auth %} to check if the user is authenticated and {% guest %} for the opposite. Optionally specify a guard as an argument. ```liquid {% auth %} user is authenticated {% endauth %} {% guest %} user is not authenticated {% endguest %} ``` ```liquid {% auth('admin') %} admin is authenticated {% endauth %} {% guest 'admin' %} admin is not authenticated {% endguest %} ``` -------------------------------- ### Guest tag with named guard and else branch Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/GuestTag.md Uses the 'admin' guard and provides an else branch for authenticated users. ```liquid {% guest 'admin' %} admin is not authenticated {% else %} admin is authenticated {% endguest %} ``` -------------------------------- ### route(string $name, string|int ...$parameters): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Filters/UrlFilters.md Generates a route URL for a given route name, with optional parameters matched positionally. ```APIDOC ## route(string $name, string|int ...$parameters): string ### Description Generates a route URL for a given route name, with optional parameters matched positionally. ### Method route ### Parameters - **$name** (string) - Required - Route name. - **...$parameters** (string|int) - Optional - Route parameters (variadic; un-named parameters are matched positionally). ### Return string - Generated route URL. ### Example ```liquid {{ 'home' | route }} {{ 'users.show', 42 | route }} ``` ``` -------------------------------- ### ViteTag parseTokenStream() method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/ViteTag.md Parses entrypoints and attributes. Throws SyntaxException with SYNTAX_ERROR if no entrypoint or non-string entrypoint. ```php protected function parseTokenStream(TokenStream $tokens): void ``` -------------------------------- ### mapLiquidExceptionToLaravel() method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Always throws a ViewException, never returns. Wraps a LiquidException with a formatted message and a mapped previous exception. ```php /** * @return never-return * * @throws ViewException */ protected function mapLiquidExceptionToLaravel(LiquidException $e, string $path): void ``` -------------------------------- ### Basic guest tag usage Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/GuestTag.md Renders the body when the user is not authenticated. ```liquid {% guest %} user is not authenticated {% endguest %} ``` -------------------------------- ### getTemplateNameFromPath method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Declares the method that converts an absolute view path to its Laravel view name by reversing the view finder's path-to-name map. Throws FileNotFoundException with message 'Template not found from path: {path}' when no registered view matches. ```php /** * @throws FileNotFoundException */ public function getTemplateNameFromPath(string $path): string ``` -------------------------------- ### getTemplateNameFromPath(string $path): string Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCompiler.md Converts an absolute filesystem path of a view file into its corresponding Laravel view name (e.g., 'home', 'partials.footer'). Throws an exception if no registered view maps to the given path. ```APIDOC ## getTemplateNameFromPath(string $path): string ### Description Converts an absolute filesystem path of a view file into its corresponding Laravel view name (e.g., 'home', 'partials.footer'). Throws an exception if no registered view maps to the given path. ### Method getTemplateNameFromPath ### Parameters #### Path Parameters - **$path** (string) - Required - Absolute path of a view file. ### Return - **string** - The Laravel view name corresponding to the path. ### Throws - **Illuminate\Contracts\Filesystem\FileNotFoundException** - With message `Template not found from path: {path}` when no registered view maps to the given path. ``` -------------------------------- ### viteAsset filter implementation Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Filters/UrlFilters.md PHP method that wraps `Illuminate\Support\Facades\Vite::asset()` to resolve a versioned Vite asset URL, with an optional custom build directory. ```php public function viteAsset(string $path, ?string $buildDirectory = null): string { return Vite::asset($path, $buildDirectory); } ``` -------------------------------- ### stream Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid-Facade.md Parses and streams a view in chunks. This method is a static proxy to the underlying Liquid instance and returns a generator. ```APIDOC ## stream ### Description Parses and streams a view in chunks. ### Method `stream` ### Signature `stream(string $view, array $data = []): \Generator` ### Parameters - **$view** (string) - Required - The view name to stream. - **$data** (array) - Optional - Data to pass to the view. ### Return Value - **\Generator** - A generator yielding chunks of the rendered view. ### Example ```php foreach (Liquid::stream('report') as $chunk) { echo $chunk; } ``` ``` -------------------------------- ### GuestTag class definition Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/GuestTag.md Defines the `{% guest %}` block tag, rendering its body when the current or named auth guard reports a guest user. Overrides `tagName()`, `render()`, and `compile()` from `AuthTag`. ```php class GuestTag extends AuthTag { public static function tagName(): string { return 'guest'; } public function render(RenderContext $context): string { if (auth()->guard($this->guard)->guest()) { return $this->body->render($context); } return $this->elseBody?->render($context) ?? ''; } public function compile(CompilerContext $context): void { $this->compileGuard($context, 'guest'); } } ``` -------------------------------- ### ViteTag parse() method Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Tags/ViteTag.md Parses the token stream and records entrypoints to the parse context outputs under 'vite_entrypoints'. ```php public function parse(TagParseContext $context): static { $this->parseTokenStream($context->params); $this->pushEntrypointsToContext($context->getParseContext()); return $this; } ``` -------------------------------- ### Stream a Liquid template response Source: https://github.com/keepsuit/laravel-liquid/blob/main/README.md Use response()->stream() with Liquid::stream() to send a template as it renders, avoiding building the whole output in memory. The stream yields chunks that are echoed directly. ```php return response()->stream(function () { foreach (Liquid::stream('home', ['name' => 'World']) as $chunk) { echo $chunk; } }); ``` -------------------------------- ### Liquid::parse method signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/Liquid.md Parses a Laravel view name into a Keepsuit\Liquid\Template. Throws FileNotFoundException if the view cannot be resolved, and SyntaxException on parse errors when app.debug is enabled. ```php public function parse(string $view): Template ``` -------------------------------- ### getTags(): array signature Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LaravelLiquidExtension.md Returns an array of Keepsuit\Liquid\Tag subclasses. Registers tags: vite, csrf, session, error, env, auth, guest. ```php public function getTags(): array ``` -------------------------------- ### Clear cached artifacts Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/LiquidCacheCommand.md These commands clear the compiled Liquid template artifacts. Note that view:cache handles only Blade views; use liquid:cache for Liquid views. ```bash php artisan optimize:clear php artisan view:clear ``` -------------------------------- ### Usage in LiquidDataSource::resolve() Source: https://github.com/keepsuit/laravel-liquid/blob/main/_autodocs/api-reference/ProfilerClockworkDumper.md Shows how ProfilerClockworkDumper is consumed internally by LiquidDataSource::resolve() to produce a timeline and merge it into the request's viewsData. ```php $timeline = (new ProfilerClockworkDumper)->dump($this->profiler); $request->viewsData = array_merge($request->viewsData, $timeline->finalize()); ```