Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Views Laravel Package

spiral/views

Spiral Views provides a view manager and rendering engine selector for Spiral apps, letting you configure and switch template engines consistently. Lightweight, tested, and type-safe, with docs and framework integration via the Spiral Framework bundle.

View on GitHub
Deep Wiki
Context7

Getting Started

Begin by installing the package via Composer and enabling the ViewsBootloader in your Spiral application’s bootloader stack (app/src/Application/Bootloader/AppBootloader.php). Configure view paths and engine adapters via config/views.php (or via environment variables). The first use case is typically rendering a simple template in a controller:

public function index(Factory $view): Response
{
    return $view->render('home/index', ['title' => 'Welcome']);
}

Start by checking the src/View/FactoryInterface and default engine adapters (e.g., RawEngine, Plates, or Twig integrations) in config/views.php.

Implementation Patterns

  • Dependency Injection: Inject Spiral\View\FactoryInterface (or Spiral\View\RendererInterface) into controllers, services, or middleware for consistent rendering.
  • Template Namespaces: Use namespace => path mapping in config to organize templates (e.g., admin::dashboard, shop::cart) and avoid path collisions.
  • Layout Composition: Define master layouts in resources/views/layouts/main.phtml and extend them in child templates using {{ $layout->extend('layouts/main') }} or equivalent engine syntax.
  • Partial Reusability: Render reusable blocks with $view->render('components/header', $data) inside templates or controllers.
  • Custom Engines: Implement Spiral\View\EngineInterface to plug in custom or newer template engines (e.g., Blade, Latte), then register them via config.

Gotchas and Tips

  • Engine adapter names must match config keys (e.g., 'engines' => ['php' => PhpEngine::class]); mismatched names cause silent fallbacks or exceptions.
  • Path resolution is case-sensitive on Linux; ensure template filenames and render() calls match exactly.
  • Rendering fails silently if template path isn’t in configured paths — use @var docblocks and debug with Factory::getTemplatePath($name) in dev.
  • Avoid injecting Factory into view templates themselves — pass data explicitly; circular dependencies can occur.
  • Extensibility: Extend Spiral\View\View to add global variables, global helpers, or custom render() decorators.
  • Since the package hasn’t been updated since 2019, verify compatibility with newer Spiral versions (especially v3+); consider forking or adopting alternatives like spiral/blade if you need modern features (e.g., component slots, hot reloading).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4