?Using the Custom Profile Data Tag
by Ryan Irelan
If you’ve ever built an ExpressionEngine site with significant membership capabilities, you may have run into the less-than-ideal situation that is the Member Profile Templates.
For the uninitiated, Member Profile Templates in EE are not the same as normal templates that you create and organize into template groups. Member Templates do not parse standard EE tags and they can be difficult to style to match the rest of your website.
In most cases I bypass the Member Templates completely and use the User Module from Solspace. The module allows you to implement all of the membership functionality in your regular EE templates. The User Module isn’t free and I’m sure at $90 some people probably think twice about picking it up.
(To me it’s worth every dollar plus some just because of the hours it saves me during implementation.)
However, for very simple member implementations where you only need to view member profile data, EE does give you a very handy tag without the need to purchase an extra module. The tag is called the Custom Profile Data tag and it allows you to display member profile data in your normal EE templates.
Here’s an example showing the total entries for the logged-in user.
{exp:member:custom_profile_data} {total_entries} {/exp:member:custom_profile_data}
In a recent project this tag came in handy when I needed to display information on the page based on a custom member field.
Let’s say you are building a social networking website for professional boxers. This is where boxers go to interact with their community. You probably know that in boxing boxers are broken up into weight classes. So, in their member profile, each user has to specify to which weight class they belong. We want to use that weight class to determine what type of content is displayed on the page; featherweight boxers would see different content than heavyweight boxers.
To do this we create a custom field called weight_class
and list out all of the possible classes and then use the value of the custom field to determine which content is displayed on the page.
{exp:member:custom_profile_data} {if weight_class == 'Lightweight'} [display lightweight content here] {if:elseif weight_class == 'Heavyweight'} [display heavyweight content here] {/if} {/exp:member:custom_profile_data}
The custom_profile_data
tag will by default display the profile fields for the currently logged-in user. You can also specify which member’s data you want to show using the member_id
parameter. If you are using the custom_profile_data
tag in a template, you should disable Template Caching for that template. Not doing so may have some unintended consequences.
Read the documentation for the entire list of variables that are available inside the custom_profile_data
tag.