【问题标题】:Easy Drupal PHP Concatenation Assistance简单的 Drupal PHP 连接帮助
【发布时间】:2012-06-25 03:55:40
【问题描述】:

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

当我输入此代码时:

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

分成两行

关于
詹姆斯

...而不是...

关于詹姆斯

请帮我连接。

【问题讨论】:

  • 应该阅读
    about
    james
    而不是
    About James

标签: drupal drupal-7 concatenation drupal-themes


【解决方案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 标记一起使用。如果您有任何问题,请告诉我们,让我们尝试解决:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多