Hello all - I'm currently working on a project using the "Members" section of Umbraco. I've got some code working, but I am hoping to get a few different items built in. Here are some items I want to accomplish:
Full faculty/staff list (sortable - via jQuery & Query Strings)
With headshot / title / etc.
Individual Faculty/Staff pages with Bios
Again, with headshot / title / and even more
Departmental Faculty/Staff pages (based on a Parameter?? - Sorted by "Dept Head - Faculty - Staff - Emeritus" [all member groups])
Similar to Item 1, but ONLY showing specific departments
I'm hoping I can do this in two macros at most (one for the full list and one for the departmental pages. I'm moreso in need of guideance for the logic on #3 (sorting the items, or whatever) and the syntax for showing the images within the "Else" of the code below, I'll fight through the jQuery/QueryString sorting later. I've tried mimicing the line:
var headshot = item.getProperty.....;
In the else, it saves, but crashes the frontend.
Here's what I have that does #1 and 2, to some extent:
@using umbraco.cms.businesslogic.member
@{
var memberId= HttpContext.Current.Request.QueryString["id"];
if(memberId != null) {
@* Individual Profile - Show Member based off of QueryString ID *@
var member = new Member(Convert.ToInt32(memberId));
var headshot = member.getProperty("headshot").Value.ToString();
@* Pull "User Name" from Members Section *@
var userName = member.Text;
@* Display properties *@
<h2>@userName</h2>
<img src="@headshot" />
<p>Other variables filled with properties</p>
} else {
@* Full list of members if there is no ID in Query String *@
var members = Member.GetAll;
<h2>All Members</h2>
foreach(var item in members){
var member = new Member(Convert.ToInt32(@item.Id));
<h3><a href="[email protected]">@item.Text</a></h3>
<p><strong>Email:</strong> @item.Email</p>
}
}
}
Thanks in advance for any help. Members currently will not have access to update their profiles, data will be updated from the backend.
Using the following code, I can get the "title" from the Members Profile. However, when I add ANY other property (phone, headshot, etc) the full list breaks.
@usingumbraco.cms.businesslogic.member@{varmemberId=HttpContext.Current.Request.QueryString["id"];if(memberId!=null){@* Individual Profile - Show Member based off of QueryString ID *@varmember=newMember(Convert.ToInt32(memberId));@* Pull "User Name" from Members Section *@varuserName=member.Text;@* Pull properties for use in public profile*@ varheadshot=member.getProperty("headshot").Value.ToString();vartitle=member.getProperty("titles").Value.ToString();varphoneNumber=member.getProperty("phone").Value.ToString();@* Display properties *@<h2>@userName</h2><imgsrc="@headshot"/><p>@title</p><p>@phoneNumber</p>}else{varmembers=Member.GetAll;<h2>All Members</h2>foreach(variteminmembers){<p>@item.Text <br />@item.getProperty("titles").Value.ToString()</p>}}}
Okay, so now I'm even MORE confused. Your code worked perfectly. But I'm still confused as to why the "titles" worked without the IF statement. Any ideas?
probably you've added the phoneNumber and other properties later and haven't filled in those information for some of the members. that's why you get error.
it's a best practice to always check if the item has that property then try to retrieve the value.
if that was the solution please mark it as solved.
Member Profile Pages
Hello all - I'm currently working on a project using the "Members" section of Umbraco. I've got some code working, but I am hoping to get a few different items built in. Here are some items I want to accomplish:
I'm hoping I can do this in two macros at most (one for the full list and one for the departmental pages. I'm moreso in need of guideance for the logic on #3 (sorting the items, or whatever) and the syntax for showing the images within the "Else" of the code below, I'll fight through the jQuery/QueryString sorting later. I've tried mimicing the line:
In the else, it saves, but crashes the frontend.
Here's what I have that does #1 and 2, to some extent:
Thanks in advance for any help. Members currently will not have access to update their profiles, data will be updated from the backend.
Using the following code, I can get the "title" from the Members Profile. However, when I add ANY other property (phone, headshot, etc) the full list breaks.
Hi Greg,
in foreach check if the member has got the property first like below:
@if(item.HasProperty("phoneNumber"))
{
item.getProperty("phoneNumber").Value;
}
Okay, so now I'm even MORE confused. Your code worked perfectly. But I'm still confused as to why the "titles" worked without the IF statement. Any ideas?
probably you've added the phoneNumber and other properties later and haven't filled in those information for some of the members. that's why you get error.
it's a best practice to always check if the item has that property then try to retrieve the value.
if that was the solution please mark it as solved.
Thanks
Ali
is working on a reply...