Member List Custom Field for EE2
As an exercise for myself in figuring out the new Custom Field API, I have produced a custom field type that adds a list of your current site members to your publish forms. It also allows you to display different aspects of the selected member’s data in your templates such as email, screen name, group title.
I thought I might as well share it in case someone finds it useful.
There are things that aren’t supported yet which I will be implementing such as restricting to member groups and returning custom member fields.
Tip of the hat goes to Leevi Graham’s Member List field type for EE 1.6.x which I have been using for a while now, and inspired the creation of this field type for EE2.0
Download cki.member_list.ee_addon
Requirements
- ExpressionEngine 2.0
Installation
- Copy
ft.cki_mblist.phpto yoursystem/expressionengine/fieldtypes/folder. - Select CKI Member List as the field type when creating a new custom field type
How to use
The field type supports single tag and tag pairs, depending on whether you want more than one element of member data at any one time.
The member_id of the selected member can be produced by simply using the Field name of your custom field with no parameters. If you want to retrieve a specific item of member data, you can use the get parameter to specify what data you want returned.
Simple Example
Lets say you have defined a custom field with a field label of Member_list and field name member_list and through the publish form selected a member with an ID of 3. You can produce the Member ID of the selected member by simply calling the field name tag on its own:
{exp:channel:entries channel="blog"}
<p>You selected member ID {member_list}</p>
{/exp:channel:entries}
Returns:
<p>You selected member ID 3</p>
Parameter Example
Using the same member you have selected in the above example, we can retrieve this member’s email address by using the get parameter:
{exp:channel:entries channel="blog"}
<p>You selected member email is {member_list get="email"}</p>
{/exp:channel:entries}
Returns:
<p>Your selected member email is john@smith.com</p>
Tag Pair Example
If you are looking to display a block of many pieces of member data within a template, it will most be likely be useful to use the tag pairs, as they can allow you reduce the amount of markup needed. The get parameter is ignored when using tag pairs.
Using the same scenario as described in the example above, you could do the following with tag pairs:
{exp:channel:entries channel="blog"}
{member_list}
<p>Name: {screen_name}</p>
<p>Email: {email}</p>
<p>Member of: {group_title}</p>
{/member_list}
{/exp:channel:entries}
Returns:
<p>Name: John Smith</p> <p>Email: john@smith.com</p> <p>Member of: Super Admin</p>
Parameters
Get
get="screen_name"
Allows you to specify what member data to return. Accepts field names of the exp_members and exp_member_groups database tables.
Some valid field name examples:
- member_id
- username
- screen_name
- group_title
- bio
- avatar_filename
Changelog
1.1.1
- Fixed bug for when using single field tags in templates
1.1
- Separated members into member groups in publish form drop down list
- Updated member existence checker
1.0
- Initial Commit
Leave a Reply