0

我正在开发一个自定义的 drupal 用户页面,并在 php 中遇到了一个连接问题。我是一个 nube,所以提前感谢您的帮助。

当我输入此代码时:

<h2><?php echo About; ?> <?php print render($user_profile['field_first_name']); ?> </h2>

它分成两行

关于
詹姆斯

...代替...

关于詹姆斯

请帮我连接。

4

1 回答 1

1

这是因为 render() 函数将 div 和其他 html 标签添加到您的内容中。如果您检查了源代码,您将看到不必要的 div 标签。

如果你需要获取原始值,你可以试试这个。在您的 tpl.php 文件中,添加以下行:

<?php print '<pre>'.print_r($user_profile['field_first_name'], 1).'</pre>'; ?>

现在您将看到一个格式良好的变量列表。

它会说这$user_profile['field_first_name']是一个数组,它会列出整个数组。现在,找到你想要的值。在大多数情况下,它类似于$user_profile['field_first_name']['und'][0]['value'].

现在,您需要做的就是使用这个值。

<h2><?php print 'About '.check_plain($user_profile['field_first_name']['und'][0]['value']); ?> </h2>

这会将值放在同一行。注意 check_plain() 函数使该值可以安全地与另一个 html 标记一起使用。如果您有任何问题,请告诉我们,让我们尝试解决:)

于 2012-06-25T13:15:43.410 回答