Copied to clipboard

Flag this post as spam?

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


  • Jacob 1 post 21 karma points
    Apr 20, 2015 @ 12:51
    Jacob
    0

    Loop through properties

    Hello all,

    I've searched through the internet for an answer to this, but to no avail.

    I created this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using umbraco.cms.businesslogic.member
    @using System.Web
    @using System.Web.Security
    @{
        Layout = "SiteLayout.cshtml";
    }
    <h2>Member List</h2>
    @{
      var memberService = ApplicationContext.Current.Services.MemberService;
      var members = memberService.GetMembersByGroup("Active");
      var currentUser = umbraco.cms.businesslogic.member.Member.GetCurrentMember();
      var memberId = HttpContext.Current.Request.QueryString["id"];
     
    }

    @if (memberId != null ){
          var member = Umbraco.TypedMember(memberId);
     
          <h1>@member.Name profile page</h1>
          <p>@member.GetProperty("firstName").Value</p>
              <p>-1-</p>
          foreach(var property in member.Properties) {
              var prop = @property.PropertyTypeAlias;
            <p>@prop: @member.GetProperty(prop).Value</p>
          }
     
    }
    else {

      foreach(var member in members) {
          <p>Brugernavn: @(member.GetValue("username")) <br/><br> @member.Id
          Comment: <br><span style="margin-left: 50px;">@(member.GetValue("umbracoMemberComments"))</span>
          </p><br>
          <a href="[email protected]" >@(member.GetValue("username"))</a>
      }
    }

    Which makes me able to select a specific user based on ID and show his name and properties in the member section of Umbraco.

    But it lists too many. We only want self created properties to be shown and not all the default.

    As you can see below, I'm in the member section of the umbraco CMS, inside the membe template. The only thing I want to show is these specific properties, so an editor can hide or show different properties on a click.

    Can you help me? :)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 20, 2015 @ 13:36
    Jeroen Breuer
    0

    Hello,

    I think that instead of looping through member.Properties you should define the custom properties there. So if you only want to show 2 properties just do this:

    <p>alias1: @member.GetProperty("alias1").Value</p>
    <p>alias2: @member.GetProperty("alias2").Value</p> 

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft