brandnewbox.co.uk

Home of Andrew Weaver, a uk-based web developer specialised in building high-quality websites

Introducing the Followers module - Part 2

Saturday, November 29th, 2008

Andrew Weaver

Category: , ,

Part 1 of this short series created a basic friend facility. This part will build on the basics, adding some of the functions popular in such a social networking site.

Confirmation Pages

While the ability to quickly follow or unfollow a member might be desirable, it is more common to get users to confirm their actions.

For our example, we’ll use the profile page for the confirmation step.

First, we’ll remove the quick follow button from the index and use a conditional to display either a follow or remove link:

...
<
a href="{path='followers/profile'}{member_id}">{screen_name}</a
{if logged_in}
-
{if following}
<a href="{path='followers/profile'}{member_id}">Remove</a
{if:else}
<a href="{path='followers/profile'}{member_id}">Follow</a
{/if}
{
/if}
... 

If the user is already following the member, a Remove link is displayed, otherwise a Follow link is shown. Note, the is used to hide both links if noone is currently logged in.

In the profile template, we can add a block at the end to add or remove the member to the user’s friends list.

...
{exp:ajw_followers:display show="member" member_id="{segment_3}"}
    {members}
        {follow_form}
        
<h4>Confirm</h4>
        
{if following}
            
<p>You are following this member. Do you want to stop following?</p>
        
{if:else}
            
<p>Do you want to follow this member?</p>
        
{/if}
        {follow_button}
        {
/follow_form}
    {
/members}
{
/exp:ajw_followers:display} 

This again uses the conditional, and introduces the {follow_form}{follow_button}{/follow_form}. This can be used to replace the {simple_follow} variable when you require a little more control of how the follow form is generated (the {follow_form} and {/follow_form} variable pair marks the start and end of the form, and the {follow_button} variable outputs the form’s button).

Thank you page

By default, when following or unfollowing a member, the user will get a standard ExpressionEngine notification

You can redirect the user to a different “thank you” page by adding a return parameter:

{exp:ajw_followers:display show="member" member_id="{segment_3}" return="{path=followers/thanks}{segment_3}"}
... 

Email notifications

You can also send email notifications to members when they get added as a friend.

These email notifications are generated from a standard ExpressionEngine template.

As an example, create a new template called email_confirmation:

Subject{screen_name} is now following you...
{exp:ajw_followers:display show="member" member_id="{follow_id}"}{members}Hi{screen_name}.{/members}{/exp:ajw_followers:display}

{exp
:member:custom_profile_data member_id="{segment_3}"}
{screen_name} is now following you
.

Check out {screen_name}s profile here:

  
http://url.com/{member_id}

A custom field goes here... {random_info}

Thanks
.
{/exp:member:custom_profile_data} 

This template will be covnverted into the email message, and the first line (if preceded with Subject: ) will be used as the email’s Subject line.

Using a template like this allows total flexibility for the contents of the confirmation email.

To tell the follow form to use this template, add the template parameter:

... template="followers/email_confirmation" ... 

Summary

So now we have a follow/unfollow confirmation page, with an email confirmation sent to members when they are added as a friend, and a thank you page.

Part 3 explains how to display a list of friends’ entries

 

Comments

1. Ben Wilson
4th Dec 2008 at 12:11 am

hello,
I have a new (EE website)  website under development and looking for your user follower plugin to be developed for me website. What do you charge if I was to have the user profile designed? Also could you create a plugin that would allow users to post their twitter updates inside the user profile? would that work as a rss or something else?

2. Andrew Weaver
4th Dec 2008 at 9:47 am

Hi Ben,

I’ve emailed you to discuss this.

Andrew

3. .(JavaScript must be enabled to view this email address)
23rd Jan 2009 at 7:41 am

Just to make sure: It is not possible to filter weblog entries based on the followers list (entries of user I am following only), right?

4. Andrew Weaver
23rd Jan 2009 at 9:38 am

It *is* possible to display entries based on the list of people you are following, but the order in which ExpressionEngine parses templates means you have to use an embedded template.

I’ll write up an example later today.

5. .(JavaScript must be enabled to view this email address)
23rd Jan 2009 at 10:05 am

Thank you, Andrew

6. Andrew Weaver
23rd Jan 2009 at 11:32 am

I’ve added Part 3 now which explains how to do this. Let me know if you need any clarification (it looks more complicated than it is).

7. .(JavaScript must be enabled to view this email address)
23rd Jan 2009 at 12:43 pm

Thanks again, Andrew, I will buy the module!

Commenting is not available in this weblog entry.

© brandnewbox.co.uk 2004-2010