Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [62]

By Root 648 0
to bring personality to the experience

FBJS (JavaScript), used to add complex functionality and behavior to your application

Stop! Is that a I see in your page source? Unless you’ve been marking up tabular data, don’t use that tag. There are two reasons for this: first, using tables to lay out your page forces you to rewrite your FBML (HTML) if you want to move an element or iterate the design and interactions. Second, remember your goals in building your Facebook application—growth, growth, and growth. Once your application’s audience starts to grow, the extra markup associated with a table-based layout will start to ratchet up your hosting costs and potentially cause slowdowns if your server is unable to meet the demand.

Facebook provides an amazing environment for developing a following of passionate fans, but chances are you will want to expand your reach to other community platforms or even deploy your application to your own or other websites. If you’ve followed this advice and built your application with the trifecta of standards-compliant web development (and avoided the temptation of the

tag), porting your application could be as simple as adjusting CSS and updating link and form submission URLs. Soon your application architecture could go from a Facebook-only structure to something like Figure 6-2.

Figure 6-2. Addition of interfaces to the shared backend logic

A well-structured Facebook application built using standards-compliant techniques permits you to iterate presentation, content, and application behavior independently of each other. It allows you to determine the logic that will be followed as Facebook members use and share your application, and then adjust layout and copy to make that as simple (or complicated) as you like. Finally, it allows your markup to be lightweight and quick to transfer, keeping your bills down and user satisfaction up!

Resources


Two-Faced Django (http://www.lethain.com/entry/2007/dec/04/two-faced-django-part-1-building-project-exists-si/)

A series of articles by developer Will Larson detailing how he created an application that works in both Facebook and as a simple web application outside the Facebook ecosystem.

W3C HTML Validator (http://validator.w3.org/)

An indispensable tool. Make sure your HTML is fully standards-compliant before adapting it to fit the FBML format.

Displaying a User’s Name


Problem


How do I display a user’s name?

Solution


Use the 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).

“Jay Goldman”

“ Yourself”

shownetwork

bool

false

Displays

®Online Book Reader