[6.x] Adds Blade Component Support to Antlers#12424
Merged
jasonvarga merged 3 commits intostatamic:masterfrom Sep 23, 2025
Merged
[6.x] Adds Blade Component Support to Antlers#12424jasonvarga merged 3 commits intostatamic:masterfrom
jasonvarga merged 3 commits intostatamic:masterfrom
Conversation
Member
|
This is awesome. One thing I noticed though is that there is a little bit of scope inheritance. Take this example, where I'm on the home page and don't provide the {{ title }}
{{ collection:articles }}
<x-card />
{{ /collection:articles }}{{# card.antlers.html #}}
<div>{{ title }}</div>You get this: Home
<div>Home</div>
<div>Home</div>
<div>Home</div>It happens regardless of whether I define |
Contributor
Author
|
The extra |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds Blade component support to Antlers. With the changes in this PR,
template authors can now write code like the following, directly in their Antlers templates:
{{ collection:pages }} <x-card :$title /> {{ /collection:pages }}Authoring Blade Components
In addition to using Blade components within your Antlers templates, you may now author Blade components using Antlers. To help with this, Antlers now supports the
@propsand@awaredirectives.When authoring Blade components using Antlers, the
@propsand@awaredirectives accept Antlers code, not PHP.As an example, the following applies an Antlers modifier to the default
titlevalue:@props([ 'title' => 'the default title' | upper ]) The Title: {{ title }}You may also use attributes, just like in Blade:
Additional Modifiers
This PR also includes two new modifiers, to help improve the experience when authoring components.
The first is the
is_stringmodifier, which checks if the provided value is a string:{{ if slot | is_string }} {{ /if }}The second is the
has_actual_contentmodifier, which checks if the provided value contains any actual content. This logic is the same as Blade's{{ $slot->hasActualContent() }}method:{{ if slot | has_actual_content }} {{ /if }}The modifier is an alternative to calling the method, which also works:
{{ if slot->hasActualContent() }} {{ /if }}Component Scope
Unlike when using partials, components do not inherit the current scope. Custom variables, and variables created within the components are not shared with the inner or outer scope (except for slots).
You may also access the current component instance inside the slot content, just like in Blade: