active icon indicating copy to clipboard operation
active copied to clipboard

Can't pass url parameter

Open xitude opened this issue 7 years ago • 7 comments

I have a marketplace url with a slug to define the category, how does one pass the parameter into the active helper?

E.g. marketplaces/cars active('marketplace.show', $slug')

xitude avatar Jun 23 '17 22:06 xitude

You should be able to use the route() helper here - active(route('marketplace.show', $slug)).

Let me know how it goes!

dwightwatson avatar Jun 24 '17 01:06 dwightwatson

@dwightwatson did not work my partial looks like this.

<ul class="dropdown hover-effect">
        <li class="dropdown-item {{ active('marketplaces') }}">
            <a href="{{route('marketplaces')}}">All Marketplaces</a>
        </li>
    @foreach(\WC\Listings\Marketplace::all() as $marketplace)
        <li class="dropdown-item {{ active(route('marketplace', $marketplace->slug)) }}">
            <a href="{{route('marketplace', $marketplace->slug)}}">{{$marketplace->title}}</a>
        </li>
    @endforeach
</ul>

The link outside the loop works as expected none of the loop items active state works.

xitude avatar Jun 24 '17 09:06 xitude

Sorry about the delay on this, been juggling a bunch of other things. I think it's expected that if you pass a URL that it will still return the active class as expected. Let me take a look.

dwightwatson avatar Jun 28 '17 00:06 dwightwatson

I think I've got this working on dev-master now - would you mind trying it out and letting me know how you go? If it's all good I'll tag a new release.

dwightwatson avatar Jun 28 '17 01:06 dwightwatson

@dwightwatson I may have run into a similar issue:

Try this:

Route::get('/test/{id}', function ($id) {
    return json_encode(is_active(\route('test', 8)));
})->name('test');

Playing around ids 8 and 88. If the route is in the form of /test/8?page=1 the above will fail of course. So I tried

return json_encode(is_active('test/8*'));

But then 8 and 88 will BOTH return true. I can't use (?) because that seems to also be a wildcard and they will both fail...

Any suggestions on how to proceed if the URL is in that format?

usernotnull avatar Oct 06 '20 21:10 usernotnull

@dwightwatson I may have run into a similar issue:

Try this:

Route::get('/test/{id}', function ($id) {
    return json_encode(is_active(\route('test', 8)));
})->name('test');

Playing around ids 8 and 88. If the route is in the form of /test/8?page=1 the above will fail of course. So I tried

return json_encode(is_active('test/8*'));

But then 8 and 88 will BOTH return true. I can't use (?) because that seems to also be a wildcard and they will both fail...

Any suggestions on how to proceed if the URL is in that format?

I eventually ended up with the more verbose solution below: return json_encode(is_active(\route('test', 8)) || is_active(\route('test', 8) . '?q=*'));

usernotnull avatar Oct 07 '20 10:10 usernotnull

Clearly that’s not desirable behaviour, the query string shouldn’t affect the output. Happy to take a look at any PR that can resolve it clearly.

dwightwatson avatar Oct 07 '20 10:10 dwightwatson