I would like to insert a slideout alert bar/notification into every single page in my Drupal website. The important thing is, drupal needs to check if the user role is member and display the alert bar only for members, not anonymous users. What is the easiest/most clever way to do that? Using template preprocess functions? How should the code look like?
By alert bar I mean this: http://jsfiddle.net/FxfHc/600/
body {
padding: 0;
}
#alert {
position: fixed;
}
#alert:target {
display: none;
}
.alert {
background-color: #c4453c;
color: #f6f6f6;
display: block;
font: bold 16px/40px sans-serif;
height: 40px;
position: fixed;
text-align: center;
text-decoration: none;
right: -130px;
width: 85px;
padding: 20px;
-webkit-animation: alert 1s ease forwards;
-moz-animation: alert 10s ease forwards;
-ms-animation: alert 1s ease forwards;
-o-animation: alert 1s ease forwards;
animation: alert 1s ease forwards;
}
@-webkit-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-moz-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-ms-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-o-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
<div>Some content</div>
<div id="alert">
<a class="alert" href="#">Click me</a>
</div>
<div>more content</div>
If you want it on every page then you have to put your code in page.tpl.php template file. If you have more than 1 page template you may place code in some include file....and include it in every page template. Just to avoid code repetition.
And you can check for current user role something like:
global $user;
if (in_array("member", $user->roles)) {
...your block here...
}
Something like that...