Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    Apr 25, 2011 @ 17:38
    FarmFreshCode
    0

    Display All Members - With links to Public Profile Page

    Hello Everyone! I am looking to create an employee directory page. I am using v4.7 of Umbraco. Im still young to Umbraco so the more detail intruction provided the better.

    I want to list all of my members in a paginated list within my "Directory.aspx" page. I would like to show the Member Name and a few other basic items like this:

    The names would be links to a "page" (http://mysite.com/directory/MyName) that showed all of the members information (such as bio, interests, ect). I was reading this post: http://bit.ly/gfL1BX which seems to point how to create the dynamic individual profile pages, but I haven't been able to get that far.

    Is there a package, or anything better than using "Members" to set something like this up? Does anyone use XSLT to accomplish something like this that they wouldn't mind sharing?

    Thanks in advance.

     

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 25, 2011 @ 18:25
    Damiaan
    1

    Hi something to start with in your template

    <umbraco:Macro runat="server" language="cshtml">
    @using umbraco.cms.businesslogic.member
    @{
    var memberId= HttpContext.Current.Request.QueryString["id"];
    }

    @if(memberId != null) {

    var member = new Member(Convert.ToInt32(memberId));
    var userName = member.Text; //not sure if this is available, could be called something else
    //var someProperty = member.getProperty("myCustomProperty").Value.ToString();
    <h2>user @userNameh2>
    <div>fill with other propertiesdiv>
    }
    else {
    var members = Member.GetAll;
    <span>Listspan>
    foreach(var item in members){
    <h1>@item.LoginNameh1>
    <span><a href="[email protected]">@item.Emaila>span>
    //var someProperty = item.getProperty("myCustomProperty").Value.ToString();
    }
    }


    </umbraco:Macro>

    check also http://our.umbraco.org/wiki/how-tos/membership-providers

  • FarmFreshCode 225 posts 422 karma points
    Apr 25, 2011 @ 22:29
    FarmFreshCode
    0

    @Damiaan Ok, this seems like it will be a great starting point for me.

    1.) I haven't been able to pull in my custom properties yet. For example one that has the alias of "phoneNumber". What would I need to do that?


  • FarmFreshCode 225 posts 422 karma points
    Apr 25, 2011 @ 22:41
    FarmFreshCode
    0
  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 25, 2011 @ 22:46
    Damiaan
    0

    Hi,

     

    I guess (never done it on Members), that you could use this :

    var someProperty = member.getProperty("aliasOfYourProperty").Value

    <span>@someProperty</span>

  • FarmFreshCode 225 posts 422 karma points
    Apr 25, 2011 @ 23:05
    FarmFreshCode
    2

    I think I have to write it differently depending on the status of the page.. (item.getProperty vs member.getProperty)... this is working for me:

    <umbraco:Macro runat="server" language="cshtml">
    @using umbraco.cms.businesslogic.member
      @{
        var memberId= HttpContext.Current.Request.QueryString["id"];
      }
        @if(memberId != null) {
       
            var member = new Member(Convert.ToInt32(memberId));
            var userName = member.Text; //not sure if this is available, could be called something else       
          //var someProperty = member.getProperty("myCustomProperty").Value.ToString();
        <h2>user @userName</h2>
        <div>fill with other properties</div>
      var phone = member.getProperty("phoneNumber").Value.ToString();
    <span>@phone</span>
      
    }  
        else {   
        var members = Member.GetAll;    
        <span>List</span>
        foreach(var item in members){
        <h1><a href="[email protected]">@item.Text</a></h1>
        <span>@item.Email</span>
      <span>@item.Id</span>
      var phone = item.getProperty("phoneNumber").Value.ToString();
    <span>@phone</span>
      }
      }

      
    </umbraco:Macro>

    Now I just have to add in all of the other values and get it styled up. That puts me one step closer.. Thank you Damiaan

     

  • FarmFreshCode 225 posts 422 karma points
    Apr 26, 2011 @ 14:33
    FarmFreshCode
    0

    Things are working really well, but I have come to 2 questions:

    1.) How do I make entire DIVs dissapear if a member doesn't enter information for that section? For example:

    <div id="cohpa-directory-link-website"><a href="@personalURL">Personal Website</a></div>

    I would like that entire section to dissapear if the member doesn't have a personal website.

    2.) I have checkboxes and dropdown lists in my members admin area. When I pull out that information onto my website I get the numberic value (87) for the item picked and not the text value (Dean's Office). What do I need to add to fix that?

     

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 26, 2011 @ 15:38
    Damiaan
    0

    The first shouldn't be too hard.

    @if(!string.IsNullOrEmpty(personalUrl)) {
    <div><a href="@personalUrl">personal website</a></div>
    }

    The second depends a on your used datatype. 

  • FarmFreshCode 225 posts 422 karma points
    Apr 26, 2011 @ 15:47
    FarmFreshCode
    0

    Well I have a few datatypes that are checklist boxes where a user can check off a few of my pre-written options. and I would like the results to display like: "Option 1, Option 2"... but right now I am getting "87, 91"

    Pretty much the same deal with the dropdown list datatype. Where the member can select the building that they are located in. And I want the results to look like this: "Building XYZ", but I am only getting "99"

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 26, 2011 @ 16:28
    Damiaan
    0

    Oh ok.  To be honest, I never used prevalues.  So maybe someone else can catch up here.

    As far as i'm aware, you have the values as a string.  So you will have to split them up into an ary and loop them manually.  After that you can use the GetPreValueAsString for every id...  I'am typing this without code editor and without testing.  So forgive me any mistakes.

    @{
      foreach(var id in MyIntsToShow.Split(',')) {
       var myStringValue = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
       <li>@myStringValue li>
      }
    }

    So this is what it could look like in Razor.  But certain that there must be xslt solutions for this too.  Good luck!

    Edit: tested the code and now it works (if the 'MyIntsToShow' string is a comma separated list of numbers)

  • FarmFreshCode 225 posts 422 karma points
    Apr 26, 2011 @ 16:52
    FarmFreshCode
    0

    So in my admin area for the members I have a tab called basic info and I have this departments section in it.

    Then in my template I call the varible basically like this..

    var departments = item.getProperty("facultyDepartments").Value.ToString();
    <span>
    @departments</span>

    but when my HTML page renders out I get this result:

    the (87,70) should read out like Dean's Office, Legal Studies

    You can see the same issue in the image above with (Location: 88) but this is a dropdown list. But same concept. I would think I would change the way I get the value of the property..

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 26, 2011 @ 17:17
    Damiaan
    0

    Hi,

    what happens if you replace the <span> with :

    @{
      foreach(var id in departments.Split(',')) {
       var myStringValue = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
       <li>@myStringValue li>
      }
    }
  • FarmFreshCode 225 posts 422 karma points
    Apr 26, 2011 @ 18:05
    FarmFreshCode
    0

    I just get an error: "Error loading Razor Script - Input string was not in a correct format."

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 26, 2011 @ 18:06
    Damiaan
    0

    and what about

    foreach(var id in departments) { 
  • FarmFreshCode 225 posts 422 karma points
    Apr 26, 2011 @ 18:21
    FarmFreshCode
    0

    So I changed it to this..

    @{
      foreach(var id in departments) {
       var myStringValue = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
        <li>@myStringValue</li>
      }
    }

    and I got a list like this..

    Which is weird because my selections are "Deans List" and "Legal Studies" no idea where that is pulling from

  • Daniel Bardi 927 posts 2562 karma points
    Apr 27, 2011 @ 21:23
    Daniel Bardi
    0

    Try this:

      var departments = @item.getProperty("facultyDepartments").Value.ToString().Split(new[],',');
      @foreach(var id in departartments) {
        <li>@umbraco.library.GetPreValueAsString(Convert.ToInt32(id));</li>
      }
  • FarmFreshCode 225 posts 422 karma points
    Apr 27, 2011 @ 21:29
    FarmFreshCode
    0

    error'd on me:

    Error loading Razor Script 
    d:\Inetpub\wwwroot\Umbraco\App_Data\TEMP\Razor\inline-7ba2a2b3bc75acb5b844a6d5e5b4967a.cshtml(164): error CS1514: { expected
  • Daniel Bardi 927 posts 2562 karma points
    Apr 27, 2011 @ 21:41
    Daniel Bardi
    0

    Try this:

      @{var departments = @item.getProperty("facultyDepartments").Value.ToString().Split(new[],',');
     
    foreach(var id in departartments) {
       
    <li>@umbraco.library.GetPreValueAsString(Convert.ToInt32(id));</li>
     
    }}

  • FarmFreshCode 225 posts 422 karma points
    Apr 27, 2011 @ 21:49
    FarmFreshCode
    0

    ha yeah, I tried that right after and still got the same error. But nice to see my "guess" wasn't crazy... although it didnt work.. :-(

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 29, 2011 @ 18:52
    Damiaan
    0

    You don't need an extra @-sign before the item variable because you started with @{ ...

      @{var departments = item.getProperty("facultyDepartments").Value.ToString().Split(new[],',');
     
    foreach(var id in departartments) {
       
    <li>@umbraco.library.GetPreValueAsString(Convert.ToInt32(id));</li>
     
    }}
  • FarmFreshCode 225 posts 422 karma points
    Apr 29, 2011 @ 19:48
    FarmFreshCode
    0

    Thanks for all your work guys.. Im still not getting past the error... so just to make sure I am dropping everything in correctly here is what I got so far..

    The image below shows where I currently am. I call the facultyDepartments variable, and only get it to call the IDs, not the titles.

    Then I change @departments with the code that you have provided and get the following result:

    If I am missing something obvious Im sorry, but I figured these screen shots might help in pointing it out.
    Thanks again for looking into this issue with me.

  • Daniel Bardi 927 posts 2562 karma points
    Apr 29, 2011 @ 19:55
  • Daniel Bardi 927 posts 2562 karma points
    Apr 29, 2011 @ 19:59
    Daniel Bardi
    0

    Instead of doing Convert.ToInt32(prevalueid)

    Try casting it like (int)prevalueid

  • FarmFreshCode 225 posts 422 karma points
    Apr 29, 2011 @ 20:59
    FarmFreshCode
    0

    Ok so I was looking at your link..I set up this code..

        @{
      var departartments = "87,70";
      foreach(var id in departartments.Split(',')) {
       var memberDepartments = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
       <li>@memberDepartments</li>
      }
    }

    Which is working to call the values correctly, (Dean's office, legal studies) however you can see that I have hardcoded those in there and thus is showing them for all my members.. I need to swap out:

      var departartments = "87,70";

    with something that pulls the code for only that specific user..like:

    var departments = item.getProperty("facultyDepartments").Value.ToString();

    but I haven't gotten that to work yet.... ALMOST THERE :-)

  • Daniel Bardi 927 posts 2562 karma points
    Apr 29, 2011 @ 21:08
    Daniel Bardi
    0

    Remove ToString() and see what happens

  • FarmFreshCode 225 posts 422 karma points
    Apr 29, 2011 @ 21:14
    FarmFreshCode
    1

    OK GOT IT!

    var departments = item.getProperty("facultyDepartments").Value.ToString(); 

    @{
      departments = item.getProperty("facultyDepartments").Value.ToString();
      foreach(var id in departments.Split(',')) {
       var memberDepartments = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
        <li>@memberDepartments</li>
      }
    }
  • Daniel Bardi 927 posts 2562 karma points
    Apr 29, 2011 @ 21:23
    Daniel Bardi
    0

    You had to re-set departments?  that's odd.

  • FarmFreshCode 225 posts 422 karma points
    Apr 29, 2011 @ 21:40
    FarmFreshCode
    0

    Well I was hoping that I would be able to convert that working example to work for a situation that only has 1 value but no luck so far. I have some values that come from a dropdown list.. but I guess it's a little different somehow

    I am able to hardcode it in there:

    @{
      var buildingLocation = "88";
      foreach(var id in buildingLocation.Split(',')) {
       var memberLocation = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
       @memberLocation
      }
    }

    but haven't been able to get it dynamically called using:

    item.getProperty("facultyBuildingLocation").Value.ToString();
  • FarmFreshCode 225 posts 422 karma points
    May 02, 2011 @ 17:06
    FarmFreshCode
    0

    Logically I would think that the code below would work for me.

    @{
      var buildingLocation = item.getProperty("facultyBuildingLocation").Value.ToString();
      foreach(var id in buildingLocation.Split(',')) {
       var memberLocation = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
        @memberLocation
      }
    }

    But I'm starting to think that because the variable "facultyBuildingLocation" comes from a single selection dropdown list in my members section, that "Split" or the "foreach" command might be throwing me an issue that is preventing me from calling the data correctly.I were to swtich out ("facultyBuildingLocation") with ("facultyDepartments") it works perfectly. So I would think there has to be something different in the way I am supposed to call multiple values from a checkbox selection v.s. a single selection from a dropdown list.


  • FarmFreshCode 225 posts 422 karma points
    Jul 14, 2011 @ 16:52
    FarmFreshCode
    0

    Hello Damiaan and Daniel Bardi

    I've take the members directory pretty far in the last 2 months and been able to populate it with all kinds of informaiton. But now I'm trying to add searching to it and not having a lot of luck yet. I thought I would post back here and see fi either of you two might have some thoughts on it since you are both the most familiar with this little project.

    You can check out the youtube video I made here: http://bit.ly/r5ruSX

    and see where I have posted on the forum already here: http://bit.ly/mOVfsM

    If you have any thoughts on how to add search to this I would greatly appreciate it.
    Thanks in advance.

     

  • ashwini 43 posts 63 karma points
    May 15, 2012 @ 19:19
    ashwini
    0

    hi everyone,

    I am very new to umbraco and i am developing a site wich was created by someone else couple of months ago. I too need to do something like FarmFreshCode here.

    I need to create a directory which has all the employees information like title, dept, email etc and the name of the employee would be clickable link which would take to the full profile of the employee page. I have no idea how to achieve this :(. My basic questions rightnow are:

    1] I was able to import all the members into database using CMS Import, but how do i display the members on directory page ?

    2] How do i create a empty profile page and use it pull data about member from database ?

    I really would appreciate if anyone could give me a starting point or any reference material as where to begin from....

    -ashwini.

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

    I'm trying to create a Members list using some things I've found on this topic. However, I'm trying to use a profile property of "headshot." I can get the image to appear on the single Member profile, but I am wanting to create a full list (the "else" portion) and everytime I use the .getProperty("headshot").Value.ToString(); I get a front-end error message.

    I'm using umbraco 4.11.3

    Any help would be appreciated. 

    Note: Using the same line of code works on the individual profile pages.

Please Sign in or register to post replies

Write your reply to:

Draft