Jigsaw: Is there support for anonymous blade components?

Created on 8 Nov 2020  路  3Comments  路  Source: tighten/jigsaw

I noticed that #440 included support for blade components鈥攂ut I couldn't tell if this included the anonymous variety. Further, can you pass data through as props?

Or would the best way to do this be via @include('_partials.header', ['page_title' => 'My Amazing Site'])?

I was hoping to do something like below but was getting errors.

<x-nav.item title="Awesome Title" href="/awesome-title" />

@props(['title', 'href'])
<a title="{{ $page->siteName }} {{ $title }}" href="{{ $href }}"
   class="ml-6 text-gray-700 hover:text-green-600 {{ $page->isActive($href) ? 'active text-green-600' : '' }}">
    {{ $title }}
</a>

Thanks!

question

All 3 comments

Ok, anonymous components seem to work just fine. It appears my error is passing $href to $page->isActive($href). So, it's still a question I would love some guidance on, but definitely out of scope from the original question. Feel free to delete or close.

What exactly is the error you're getting? Does the $page variable not exist? If that's the case it's because components, unlike includes, _don't_ inherit the parent scope. You could add an active prop and pass it $page->isActive('/awesome-title'), so that that call happens outside of the component itself, or you could even pass the whole $page into each nav item if necessary.

Yep鈥攊t appears the $page var was not available. Error:

Call to a member function isActive() on null

But like you suggested, passing in an active prop for $page fixes my issue. Thanks you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knorthfield picture knorthfield  路  3Comments

royvanv picture royvanv  路  10Comments

DRogueRonin picture DRogueRonin  路  8Comments

cossssmin picture cossssmin  路  12Comments

himan72 picture himan72  路  9Comments