2

I have 4 tabs in my user view.

When the page loads, how do I make my view display the third tab as active?

For different routes, I need to have different tabs open -

eg: - for user/home - the first tab for user/profile - the second tab

I am using Bootstrap :-

<div>
<ul class="nav nav-tabs" role="tablist">
   <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
   <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
   <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
   <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
 </ul>


<div class="tab-content">
   <div role="tabpanel" class="tab-pane active" id="home">Home</div>
   <div role="tabpanel" class="tab-pane" id="profile">Profile</div>
   <div role="tabpanel" class="tab-pane" id="messages">Messages</div>
   <div role="tabpanel" class="tab-pane" id="settings">Settings</div>
</div>

</div>
Stacy J
  • 2,721
  • 15
  • 58
  • 92
  • just add active to this fourth tab ? – Yehia Awad Nov 29 '15 at 09:05
  • I mean, how can I specify in the route, that I want the third tab open – Stacy J Nov 29 '15 at 09:08
  • it could be done several ways, the one that i can think of is to add active class to your menu through `@if($someFlags){{...}}@endif`. alternatively, check current path, [look at this question](http://stackoverflow.com/questions/17591181/how-to-get-the-current-url-inside-if-statement-blade-in-laravel-4). basically, i want to say, it's unrelated to routes, it's how you render things. – Bagus Tesa Nov 29 '15 at 10:51

1 Answers1

0

You can check the Request url is matching specific parameter:

 <li role="presentation" class={{Request::is('profile/*')?"active":""}}><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
Mina Abadir
  • 2,951
  • 2
  • 15
  • 20
  • This did not work for me. I tried http://localhost:8000/user#profile, still it is not opening the respective tabs. When I click on the tab navigation, it shows http://localhost:8000/user#profile route but don't know why it doesn't open.. – Stacy J Dec 01 '15 at 09:23
  • yes, even when i hover over the tabs, I can see on my browser, bottom left, http://localhost:8000/user#home, http://localhost:8000/user#profile, http://localhost:8000/user#message etc... – Stacy J Dec 01 '15 at 09:28
  • 2
    This has nothing to do with Laravel. It's Javascript. Ensure your JS that handles the tabs is working fine. – Mina Abadir Dec 01 '15 at 09:31
  • so are you saying, i wouldn't need class={{Request::is('profile/*')?"active":""}} – Stacy J Dec 01 '15 at 09:32
  • 1
    If you need to have the third tab active, just place the class="active" tag. I do not see any Laravel or logic need here. – Mina Abadir Dec 01 '15 at 09:54
  • Thanks, that helped - I searched for it and got this http://stackoverflow.com/questions/7862233/twitter-bootstrap-tabs-go-to-specific-tab-on-page-reload-or-hyperlink – Stacy J Dec 01 '15 at 10:14