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

Laravel Content Renderer Laravel Package

code16/laravel-content-renderer

Laravel package for rendering content blocks into HTML in a structured, extensible way. Define renderers for different content types, map data to views, and compose pages from reusable components—useful for CMS-like content, editors, and APIs.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require code16/laravel-content-renderer. The package exposes a Blade component @content for rendering structured content (e.g., JSON or arrays) as HTML. Begin by defining simple content blocks as associative arrays (e.g., ['type' => 'text', 'text' => 'Hello']), then render them in Blade with @content($content, 'default'). Start with the included block types (like text, heading) to verify basic functionality before customizing.

Implementation Patterns

  • Content-as-data architecture: Store rich content (e.g., page layouts, blog sections) as JSON in your database (e.g., Page::jsonContent column), then render via @content($content, 'context').
  • Block-type registration: Extend BaseBlockRenderer for custom blocks (e.g., CardRenderer) and bind them in a service provider using ContentRenderer::registerBlockType('card', CardRenderer::class).
  • Context-aware rendering: Pass context strings (e.g., 'hero', 'sidebar') to @content() to reuse the same content structure with different styling/behavior—e.g., @content($blocks, 'hero') vs. @content($blocks, 'card').
  • Form integration: Pair with code16/laravel-form-builder to build WYSIWYG-style content editors—save structured output as JSON and leverage the same renderer for display.

Gotchas and Tips

  • Strict type matching: Block types are case-sensitive and resolved from the type key—'Text' won’t match 'text'. Always normalize types before saving or rendering.
  • Silent failures: Unknown block types render empty output unless debugging is enabled. Use ContentRenderer::debug(true) in development to log unhandled types.
  • No auto-escaping: User-provided content (e.g., from admin inputs) must be sanitized in renderers—override renderContent() and wrap output with e() or use Blade’s {{ }} inside your renderer’s view.
  • Empty/null content: The renderer may throw if passed null or malformed JSON. Always validate or default content (e.g., @content($content ?? [], 'default')).
  • Debugging tip: Set CONTENT_RENDERER_DEBUG=true in .env or call ContentRenderer::debug() in your service provider to enable verbose logging of rendering steps.
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