Matias K. Matias K. - 6 months ago 29
Javascript Question

Dropdown menu to show after login

Alright, so I want to have a dropdown menu to hide before they login and I want the dropdown menu to show after login.
Here is the html code, but I do not know how I can do this with a function.

Help is much appreciated.

<ul class="nav navbar-nav navbar-right">
<div>
<li class="login" style="display: none;">
<a href="longsteamloginlinknothingimportant">
<img src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png">
</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<img height="15" img src="" alt="profile-avatar">
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="/"><i class="fa fa-cog"></i> Account Settings <span class="badge badge-danger"> COMING SOON </span></a></li>
<li><a href="/"><i class="fa fa-bar-chart"></i> Jackpot Stats<span class="badge badge-danger"> COMING SOON </span></a></li>
<li class="divider"></li>
<li class="dropdown-header">Account Balance</li>
<li><a href="/skins/deposit"><i class="fa fa-download"></i> Deposit <span class="badge badge-danger"> COMING SOON </span></a></li>
<li class="divider"></li>
<li class="dropdown-header">History</li>
<li class="divider"></li>
<li><a href="php/SteamAuthentication/steamauth/logout.php"><i class="fa fa-power-off"></i> Logout</a></li>
</ul>
</li>
</div>
</div>
</ul>

Answer

If you want to show some HTML conditionally using PHP, you can wrap it in a PHP conditional clause, like so:

<?php if (isLoggedIn()) { ?>
<!-- Your dropdown menu HTML here -->
<?php } ?>

Alternatively, and this is probably a better long-term option if you're building something non-trivial, you can use a template engine like Twig to render your HTML. In Twig, your HTML might look like this instead:

{% if isLoggedIn %}
<!-- Your dropdown menu HTML here -->
{% endif %}
Comments