Using views
As per the previous page, most of your pattern definitions will use the makeContext
method. This should be fine for most cases.
However, if you would like to create completely arbitrary patterns, such as organisms or templates (or indeed any other static representation), then it is possible to return a simple view from within the contextData
method. For instance, consider the following view file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{{-- /resources/views/patterns/cards/grid.blade.php --}}
<div>
<h2 class="text-xl mb-4">Grid of cards</h2>
<div class="grid grid-cols-3 gap-4">
<x:cards.card
title="Card 1"
image="https://picsum.photos/600/150"
>
<p>Quisquam incidunt aut vero cupiditate. Accusantium id veritatis veritatis.</p>
</x:cards.card>
<x:cards.card
title="Card 2"
image="https://picsum.photos/600/150"
>
<p>Necessitatibus et voluptatum autem.</p>
</x:cards.card>
<x:cards.card
title="Card 3"
image="https://picsum.photos/600/150"
>
<p>Quis id facere corrupti et incidunt molestiae vel ducimus enim.</p>
</x:cards.card>
</div>
</div>
This view could be used directly within the contextData
method as follows:
1
2
3
4
public function contextData(string $context): PatternContext|View
{
return view('patterns.cards.grid');
}
And would appear as such within Braid:

(Note how the Context tab now shows the context view instead of object-based data.)