Displaying a User’s Name

Problem

How do I display a user’s name?

Solution

Use the <fb:name> tag. Among the many options you can include, specify the uid of the user whose name you want to display (you can also use loggedinuser or profileowner).

Discussion

This tag is interesting because of the various ways that different languages deal with possessive nouns and other grammatical structures, which I can never keep straight. (Is the participle dangling? What does that even mean?) This is a great example of FBML saving you from having to add giant if/else blocks to your code. The parameters are listed in Table 6-1.

Table 6-1. Parameters for fb:name

Name

Type

Default value

Description

They see

I see

uid

uid

N/A

The Facebook user ID (uid) of the user or Page whose name you want to show. You can also use loggedinuser or profileowner. This is the only required field.

“Jay Goldman”

“You”

capitalize

bool

false

Capitalize the text if useyou is true and loggedinuser is the uid.

“Jay Goldman”

“You”

firstnameonly

bool

false

Show only the user’s first name.

“Jay”

“You”

ifcantsee

string

Empty

Alternate text to display if the logged-in user cannot access the user specified.

Specified text if they can’t see me; “Jay Goldman” if they can

“You”

lastnameonly

bool

false

Show only the user’s last name.

“Goldman”

“You”

linked

bool

true

Link to the user’s Profile.

“Jay Goldman”

“You”

possessive

bool

false

Use the possessive form (his/her/your).

“Jay Goldman’s”

“Your”

reflexive

bool

false

Use the reflexive form (himself/herself/yourself). ...

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.