简体   繁体   English

如何使用 api 调用呈现 Drupal 用户配置文件?

[英]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.

相关问题 如何在Drupal中获取用户的个人资料路径? - How do I get a user's profile path in Drupal? 如何删除Drupal profile2模块及其创建的所有用户配置文件表 - How do I remove Drupal profile2 module and all user profile tables it created 如何编辑drupal中默认用户配置文件页面上的链接选项卡? - How do I edit link tabs found on the default user profile page in drupal? Drupal 6网站将配置文件值保存到user-> data对象而不是profile_fields表,如何防止这种情况,以便我可以在视图中使用 - Drupal 6 website saving profile values to the user->data object instead of to the profile_fields table, how do I prevent this so I can use in views 如何在 drupal 8 中使用带有“多重注册”模块的用户“配置文件”模块? 删除个人资料表格重复 - How can I use user "profile" module with "multiple registration" module in drupal 8? remove profile form duplicacy 如何在Drupal 7的用户个人资料页面中添加内容? - How to add content to user profile page in Drupal 7? 如何在Drupal中向用户个人资料页面添加按钮 - How to add button to user profile page in drupal 如何在 Drupal 中打印与用户关联的配置文件 ID? - How to print profile id associated with the user in Drupal? 如何获取用户的个人资料网址? - How do I get the profile URL of a user? Drupal:如何在视图中列出与配置文件节点相关的所有节点? (不是核心配置文件)。 - Drupal: How do I list inside a view all nodes related to a profile node? (not the core profile).
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM