1

I am new to drupal, but I had a requirement, my current site using bootstrap theme. Previously there was no login and logout buttons on header. Today I got html login and logout strip from desinger. For this I have created a new block and selected bootstrap region as Navigation. Now this custom header perfectly sits at the top of the page. with static Myaccout, Logout , contactus which are sent by desinger.

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
     </div>
    <div class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Navigator</a></li>
        <li><a href="#">Contact Us</a></li>

          </ul>
          <ul class="nav navbar-nav navbar-right"> 
<li> <a href="#">My Account </a></li>
 <li> <a href="#">Log Out </a></li>
 </ul>    
        </li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</div>

But my question how to make that header dynamic like when user with out login need to show Login , and after login need to show myaccount and logout. Above code is the static html bootstrap header sent by desinger. Please suggest me how to do this?

1
  • Hi, you could render or place the user menu block in the navigation regions
    – Leopathu
    Sep 14, 2014 at 15:11

2 Answers 2

2

It can be done this way

<ul class="nav navbar-nav navbar-right"> 
<?php
global $user; 
 if($user->uid):?>
<li> <a href="#">My Account </a></li>
<li> <a href="#">Log Out </a></li>
<?php else: ?>
<li> <a href="/user">Log in</a></li>
<?php endif; ?>
</ul>

Hope it will help

0
0

Edit the code between your ul class="nav navbar-nav navbar-right"> to make it look like this:

<?php if(global $user):?>
<li> <a href="#">My Account </a></li>
<li> <a href="#">Log Out </a></li>
<?php else: ?>
<li> <a href="/user">Log in</a></li>
<?php endif; ?>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.