0

I have the following in my header:

<div id="wrapper" class="homepage itemlist com_k2 category">
  <div id="rt-header">
    <div class="rt-container">
      <div class="rt-grid-3 rt-alpha">
        <div class="rt-block"><a href="#" id="rt-logo"></a></div>
      </div>
      <div class="rt-grid-9 rt-omega">
        <div class="rt-fusionmenu">
          <div class="nopill">
            <div class="rt-menubar">
              <ul class="menutop level1 ">
                <li class="parent  root f-main-parent firstItem f-mainparent-item"> <a class="daddy item bullet" href="www.domain.com"> <span> الرئيسية </span> </a> </li>

                <li class="active root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
                <li class="root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
                <li class="root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
      <div class="clear"></div>
    </div>
  </div>

Now if you investigate the

  • elements, you will find that there is an active flag in one of them. This makes sure that the currently seen page is highlighted in navigation bar. I want to know how can I change this based on view loaded? this is how I load views:

    $this->load->view('layout/header');
    $this->load->view('home');
    $this->load->view('layout/footer');
    

    So in this case the main navigation tab should be active.

    Regards,

    3 Answers 3

    3

    I completed something similar recently. Probably not the best way, but it works for me.

    In your controller add this before your views

    $data['contact'] = 'active';
    

    Then pass the $data variable from the controller to the view

    $this->load->view('header', $data);
    

    And in your view add this to the list item

    <li class="contact <?php if(isset($contact)) {echo $contact; }">
    
    Sign up to request clarification or add additional context in comments.

    Comments

    2

    from the controller:

    set names for your menus and put the loaded menu or page name in a variable as the following:

    $data['active'] = 'menu1';
    $this->load->view('layout/header',$data);
    $this->load->view('home');
    $this->load->view('layout/footer');
    

    in the view:

    <div id="wrapper" class="homepage itemlist com_k2 category">
      <div id="rt-header">
        <div class="rt-container">
          <div class="rt-grid-3 rt-alpha">
            <div class="rt-block"><a href="#" id="rt-logo"></a></div>
          </div>
          <div class="rt-grid-9 rt-omega">
            <div class="rt-fusionmenu">
              <div class="nopill">
                <div class="rt-menubar">
                  <ul class="menutop level1 ">
                    <li class="<?php if(isset($active) && $active == 'menu1') echo 'active';  ?> parent  root f-main-parent firstItem f-mainparent-item"> <a class="daddy item bullet" href="www.domain.com"> <span> الرئيسية </span> </a> </li>
    
                    <li class="<?php if(isset($active) && $active == 'menu2') echo 'active';  ?> root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
                    <li class="<?php if(isset($active) && $active == 'menu3') echo 'active';  ?> root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
                    <li class="<?php if(isset($active) && $active == 'menu4') echo 'active';  ?> root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
          <div class="clear"></div>
        </div>
      </div>
    

    Comments

    0

    Give each menu item a distinct class or id then do it via jQuery or js

    <li class="kitchen root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
    <li class="anotherclass root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
    <li class="contact root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
    

    Then for example in the contact page you'd simply do this via jQuery:

    $(document).ready(function(){
        $(".contact").addClass("active");
    });
    

    Comments

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.