[英]How do I Render a Drupal User Profile using api calls?
I'm doing this to render a node and returning the output to an AJAX call and displaying a node inline on a page:我这样做是为了渲染一个节点并将 output 返回到 AJAX 调用并在页面上显示内联节点:
$node = node_load($nid);
$node_view = node_view($node);
echo drupal_render($node_view);
I need to be able to do the same things for a user profile...is it similar?我需要能够为用户个人资料做同样的事情......它相似吗?
It's pretty similar, you can use the following functions:它非常相似,您可以使用以下功能:
$account = user_load($uid);
$account_view = user_view($account);
echo drupal_render($account_view);
EDIT编辑
I changed the variable name to use $account
instead of $user
, just to eliminate the possibility of overwriting the global $user
variable.我将变量名称更改为使用
$account
而不是$user
,只是为了消除覆盖全局$user
变量的可能性。
The Entity API module provide a generic function to render any entity: entity_view()
that can also be used. Entity API模块提供了一个通用的 function 来渲染任何实体:也可以使用
entity_view()
。 For a user entity this should produce the same results than user_view()
.对于用户实体,这应该产生与
user_view()
相同的结果。
$account = user_load($uid);
$account_view = entity_view('user', $account);
echo drupal_render($account_view);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.