简体   繁体   English

简单的Drupal PHP串联协助

[英]Easy Drupal PHP Concatenation Assistance

I am working on a custom drupal user page and have run into a concatination question in php. 我正在一个自定义的drupal用户页面上工作,并在php中遇到了一个混淆问题。 I am a nube so thanks in advance for your help. 我是一个小伙子,所以在此先感谢您的帮助。

When I input this code: 当我输入此代码时:

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

It breaks on to two lines 它分为两行

About 关于
James 詹姆士

...instead of... ...代替...

About James 关于詹姆斯

Please help me concatenate. 请帮助我串联。

This is because render() function adds div and other html tags to your content. 这是因为render()函数将div和其他html标签添加到您的内容中。 If you checked the source, you will see unnecessary div tags. 如果检查了源代码,将看到不必要的div标签。

If you need to get the raw value, you can try this. 如果您需要获取原始值,可以尝试一下。 In your tpl.php file, add this line: 在您的tpl.php文件中,添加以下行:

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

Now you will see a nicely formatted variable listing. 现在,您将看到一个格式良好的变量列表。

it will say that $user_profile['field_first_name'] is an array, and it will list the whole array. 它会说$user_profile['field_first_name']是一个数组,它将列出整个数组。 Now, find that value you want. 现在,找到您想要的值。 In most cases, it's similar to $user_profile['field_first_name']['und'][0]['value'] . 在大多数情况下,它类似于$user_profile['field_first_name']['und'][0]['value']

Now, all you need to do is using this value instead. 现在,您需要做的就是使用此值。

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

this will put the value in same line.Note that the check_plain() function makes this value safe to be used with another html tag. 请注意,check_plain()函数使该值可以安全地与另一个html标记一起使用。 If you have any trouble, let us know and lets try to figure that out :) 如果您有任何麻烦,请告诉我们,让我们设法解决:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM