Sitelok menu based on groups

I m not sure if this is possible or not but I would like to do the following:

Have groups 1,2,3 and a menu like below

Link 1 (Available to groups 1,2 & 3)
Link 2 (Available to group 1)
Link 3 (Available to groups 1,2 & 3)
Link 4 (Available to groups 2 & 3)
Link 5 (Available to groups 1 & 3)

Or something along these lines. Is this possible?

1 Like

Yes, what you wrote is certainly possible. The key is all links are available to everyone, but some links won’t work if you are not part of the right group (essentially you’ll be told you don’t have access).

Here is how I coded my foundation menu to only display certain menu items for admins and/or members.

<li <?php if (sl_ismemberof("ADMIN")){ ?>class='has-dropdown'<?php } ?>><a href='/products'>Products</a>
   <?php if (sl_ismemberof("ADMIN")){ ?>
    <ul class='dropdown'>
        <li><a href='/products/admin'>Admin</a></li>
	<li><a href='/admin/products/article'>New Product</a></li>
    </ul>
    <?php } ?>
</li>
<li <?php if (sl_ismemberof("ADMIN")){ ?>class='has-dropdown'<?php } ?>><a href='/services'>Services</a>
   <?php if (sl_ismemberof("ADMIN")){ ?>
    <ul class='dropdown'>
        <li><a href='/services/admin'>Admin</a></li>
	<li><a href='/admin/services/article'>New Service</a></li>
    </ul>
    <?php } ?>
</li>
<li <?php if (sl_ismemberof("ADMIN")){ ?>class='has-dropdown'<?php } ?>><a href='/blog'>Blog</a>
   <?php if (sl_ismemberof("ADMIN")){ ?>
    <ul class='dropdown'>
        <li><a href='/blog/admin'>Admin</a></li>
        <li><a href='/admin/blog/article'>New Post</a></li>
    </ul>
    <?php } ?>
</li>
<li><a href='/forum' target='_blank' >Forum</a></li>
<li <?php if (sl_ismemberof("ADMIN")){ ?>class='has-dropdown'<?php } ?>><a href='/demo'>Demo</a>
   <?php if (sl_ismemberof("ADMIN")){ ?>
    <ul class='dropdown'>
        <li><a href='/demo/admin'>Admin</a></li>
    </ul>
    <?php } ?>
</li>
<li <?php if (sl_ismemberof("ADMIN")){ ?>class='has-dropdown'<?php } ?>><a href='/contact'>Contact</a>
   <?php if (sl_ismemberof("ADMIN")){ ?>
    <ul class='dropdown'>
        <li><a href='/contact/admin'>Admin</a></li>
    </ul>
    <?php } ?>
</li>

<?php if (sl_ismemberof("ADMIN")){ ?>
<li class='has-dropdown'><a href='/documentation/'>Public Documentation</a>
    <ul class='dropdown'>
        <li><a href='/admin/public-documentation/'>Admin</a></li>
	<li><a href='/admin/public-documentation/document'>New Document</a></li>
    </ul>
</li>
 <?php } ?>

<?php if (sl_ismemberof("ADMIN")){ ?>
<li class='has-dropdown'><a href='/private-documentation/'>Private Documentation</a>
    <ul class='dropdown'>
	 <li><a href='/admin/private-documentation/'>Admin</a></li>
        <li><a href='/admin/private-documentation/document'>New Document</a></li>
    </ul>
</li>
 <?php } ?>

<li <?php if (sl_ismemberof("ADMIN")){ ?>class='has-dropdown'<?php } ?>><a href='#' class='glider-toggle' data-glider='donate-glider'>Funding</a>
   <?php if (sl_ismemberof("ADMIN")){ ?>
    <ul class='dropdown'>
        <li><a href='/funding/admin'>Admin</a></li>
    </ul>
    <?php } ?>
</li>

<?php if ($slpublicaccess) { ?>
<li><a href='#' class='glider-toggle' data-glider='login-glider'>Login/Register</a></li>
<?php } // Hide ?>

<?php if (!$slpublicaccess) { ?>
<li class='has-dropdown'><a href='/demo'><?php echo $slname; ?></a>
    <ul class='dropdown'>
       <li><a href="/admin/demo/">Account Settings</a></li>
     <?php if (sl_ismemberof("ADMIN")){ ?>
       <li><a href="/slpw/">Admin Settings</a></li>
     <?php } ?>
       <li><a href="/slpw/sitelokpw.php?sitelokaction=logout">Logout</a></li>
    </ul>
</li>
<?php } ?>
3 Likes

Brandon, thank you. That is exactly what I was looking for.

1 Like

You are very welcome. I’m happy I could help.

I want to only display a logout menu item when users are logged in. Looking through the Sitelok API, I don’t see a function to determine if the user is logged in.

Hi Mike,

Sorry just spotted this question. The variable $slpublicaccess is set to true if a user is a visitor and false if they are logged in. So you can use the following to display a logout link only for logged in users.

<?php if (!$slpublicaccess) { ?>

Logout link here

<? } ?>

Sitelok needs to be controlling the page for the variable to be set of course though. You can use the special PUBLIC usergroup on non members pages to allow visitors to see the page and Sitelok to still have control. Contact me via support if you need any help anyway.

2 Likes

Thank you very much! That is exactly what I needed.