Skip to content

Add practical examples showing facade alternatives to Antlers tags #1770

Description

@jonathan-bird

The current Blade documentation shows two approaches for using Statamic features in Blade:

  1. Antlers Blade Components (<s:glide>) - verbose for simple use cases
  2. Fluent tags (Statamic::tag('glide')) - awkward syntax, not discoverable

However, there's a cleaner approach using facades that isn't documented at all.

For example: Image Manipulation (Glide), the docs currently show:

{{-- Using fluent tags --}}
<img src="{{
 Statamic::tag('glide')->src('test.png')->width(1280)->height(800)->fetch() }}"
/>

{{-- Using Antlers Blade Components --}}
<s:glide src="test.png" width="1280" height="800">
 <img src="{{ $url }}" />
</s:glide>

The second approach is clunky if you're just wanting the URL, so you're forced to use Statamic::tag() everywhere if you just want the data, but there's a much cleaner facade approach that isn't documented:

<img src="{{ Image::manipulate('test.png', ['w' => 1280, 'h' => 800]) }}" />

I prefer using Facades because it's more Laravel-like and familiar to developers, and also better IDE autocomplete support. It's also a cleaner syntax for simple use cases.

Suggestion

The Blade documentation should include a section showing facade equivalents for common Antlers tags. For example:

Collections:

// Instead of: Statamic::tag('collection:wheels')->limit(3)
Collection::findByHandle('wheels')->queryEntries()->limit(3)->get()

Taxonomies:

// Instead of: <s:taxonomy:categories>
Taxonomy::findByHandle('categories')

Navigation:

// Instead of: <s:nav:main>
Nav::find('main')->tree()

This would help developers transitioning from Antlers or building custom Blade components discover the most appropriate API for their needs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions