Hide elements for certain groups
Permalink 1 user found helpful
Hey guys,
I've been working with HTML/CSS for a while, but all this PHP is new to me. For a part of my website, I want content enclosed in a <div> to be hidden or displayed depending on whether a user is part of a certain group. How on earth do I do that? There are only two groups (students, teachers) and I want certain div elements only viewable for teachers. Please help. Thanks in advance!
For example, would this hide the logo if the user is part of the group titled "students":
I've been working with HTML/CSS for a while, but all this PHP is new to me. For a part of my website, I want content enclosed in a <div> to be hidden or displayed depending on whether a user is part of a certain group. How on earth do I do that? There are only two groups (students, teachers) and I want certain div elements only viewable for teachers. Please help. Thanks in advance!
For example, would this hide the logo if the user is part of the group titled "students":
<?php $u = new User(); $g = Group::getByName('students'); if($u->inGroup($g)) { $("div").show(); } else { $("div").hide(); } ?> <div id="logo"> <img src="/img/logo.png" alt="Endowr Logo" /> </div>
or
The thing to note in either of those is that anything outside of the <?php ?> stuff is just outputted to the browser as is. Typically that is html code like above.
Is actually some jQuery(a javascript library code). In jQuery's case the dollar sign is a shorcut for writing jQuery("div").show(); whereas in php's case a dollar sign simply defines a string of text as a variable.