在Drupal 7中滑出警报栏

时间:2015-10-12 10:06:05

标签: drupal drupal-7 notifications alert

我想在Drupal网站的每个页面中插入一个滑出警报栏/通知。重要的是,drupal需要检查用户角色是否是成员,并仅为成员而不是匿名用户显示警报栏。最简单/最聪明的方法是什么?使用模板预处理功能?代码应该如何?

通过提示栏我的意思是: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>

1 个答案:

答案 0 :(得分:0)

如果你想在每个页面上使用它,那么你必须将你的代码放在page.tpl.php模板文件中。如果您有超过1个页面模板,您可以将代码放在某个包含文件中....并将其包含在每个页面模板中。只是为了避免代码重复。

您可以检查当前用户角色,例如:

global $user;
if (in_array("member", $user->roles)) {
  ...your block here...
}

像这样......