【问题标题】:drupal show/hide certain fields based on authordrupal 根据作者显示/隐藏某些字段
【发布时间】:2010-10-31 09:26:17
【问题描述】:

我想根据当前用户是否是正在查看的节点的作者,在我的 Drupal 视图中显示/隐藏某些字段。

我安装了Views Custom Field module,它似乎允许这样做,但我不了解 PHP,所以想知道是否有人可以帮助我编写 PHP 代码。

【问题讨论】:

    标签: drupal


    【解决方案1】:

    类似这样的东西(检查 $data 是否有 uid,可能名称不同):

    global $user;
    if ($user->uid == $data->uid) {
      print 'something';
    }
    

    【讨论】:

    • 谢谢,这很有帮助。如果你不介意的话,再问一个问题。
    • 如何找到我要打印的字段名称?
    • print_r($data);您将在视图结果中看到 $data 的一些内部
    • 您好,感谢您的帮助,我到了那里。我有以下代码,
    • to_do; if ($user->nid == $data->nid) { print '[buttons]'; } ?> 上面没有显示任何内容,但如果我只添加 然后它起作用了,所以我假设它可能不使用 UID ?当我运行 print_r($data);我得到以下输出: stdClass Object ( [nid] => 72 [node_title] => another test task [to_do_deadline] => [to_do_priority] => 1 [to_do_start_date] => [to_do_item_status] => 2 [to_do_nid] => 72)谢谢你的帮助,顺便说一句,我真的很感激
    猜你喜欢
    • 1970-01-01
    • 2011-07-15
    • 2012-09-27
    • 2012-06-15
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2013-09-17
    • 2017-02-02
    相关资源
    最近更新 更多