Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Greg McMullen 49 posts 195 karma points
    Feb 28, 2013 @ 16:54
    Greg McMullen
    0

    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:

    1. Full faculty/staff list (sortable - via jQuery & Query Strings)
      1. With headshot / title / etc.
    2. Individual Faculty/Staff pages with Bios
      1. Again, with headshot / title / and even more
    3. Departmental Faculty/Staff pages (based on a Parameter?? - Sorted by "Dept Head - Faculty - Staff - Emeritus" [all member groups])
      1. 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.

  • Greg McMullen 49 posts 195 karma points
    Mar 01, 2013 @ 17:23
    Greg McMullen
    0

    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.

    @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));
            @* Pull "User Name" from Members Section *@
            var userName = member.Text; 
            @* Pull properties for use in public profile*@
    var headshot = member.getProperty("headshot").Value.ToString(); var title = member.getProperty("titles").Value.ToString(); var phoneNumber = member.getProperty("phone").Value.ToString(); @* Display properties *@ <h2>@userName</h2> <img src="@headshot" /> <p>@title</p> <p>@phoneNumber</p> } else { var members = Member.GetAll; <h2>All Members</h2> foreach(var item in members){ <p>@item.Text
    <br />@item.getProperty("titles").Value.ToString()</p> } } }
  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Mar 01, 2013 @ 18:27
    Ali Sheikh Taheri
    101

    Hi Greg,

    in foreach check if the member has got the property first  like below:

    @if(item.HasProperty("phoneNumber"))
    {
    item.getProperty("phoneNumber").Value;

     

     

  • Greg McMullen 49 posts 195 karma points
    Mar 01, 2013 @ 19:27
    Greg McMullen
    0

    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?

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Mar 01, 2013 @ 20:48
    Ali Sheikh Taheri
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft