dreamerdan
dreamerdan

Reputation: 41

Loading 'view' to a direct tab from controller

I have a code that lies in the third 'gallery' tab. 'Wall' is the active tab when the page loads.

<ul class="nav nav-tabs">
      <li class="active"><a data-toggle="tab" href="#my-wall">Wall</a></li>
      <li><a data-toggle="tab" href="#profile">Profile</a></li>
      <li><a data-toggle="tab" href="#gallery">Gallery-Photos</a></li>
  </ul>

I'd like to load the view from the controller directly to the 'gallery' tab. Is it possible to simply add the tab's ID as follow in code igniter or is there another way:

$this->load->view('wall#gallery'), $data);  

Appreciate all feedback.

Upvotes: 0

Views: 350

Answers (1)

Danish Ali
Danish Ali

Reputation: 2352

You can do this easily like this.

Remove active class from all tabs and send a specific variable to view. Base on that variable add the condition to active your desired tab.

$data['active_tab'] = 'gallery';
$this->load->view('wall', $data);  

View

<ul class="nav nav-tabs">
      <li <?php if($active_tab == 'my-wall'){ echo "class='active'";}?> ><a data-toggle="tab" href="#my-wall">Wall</a></li>
      <li <?php if($active_tab == 'profile'){ echo "class='active'";}?>  ><a data-toggle="tab" href="#profile">Profile</a></li>
      <li <?php if($active_tab == 'gallery'){ echo "class='active'";}?> ><a data-toggle="tab" href="#gallery">Gallery-Photos</a></li>
  </ul>

Upvotes: 1

Related Questions