Copied to clipboard

Flag this post as spam?

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


  • Ole Kristian Losvik 22 posts 73 karma points
    Feb 20, 2015 @ 22:06
    Ole Kristian Losvik
    0

    Get member properties in macro by members email

    Trying to make a macro which looks up some of member profile properties based on a lookup by a member email supplied as a macro parameter:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using System.Web.Mvc.Html
    @using ClientDependency.Core.Mvc
    @using Umbraco.Web
    @using Umbraco.Web.Controllers
    @using Umbraco.Core
    @using Umbraco.Core.Models
    @using Umbraco.Core.Services
    
        @{
        string authorUsername;
        string authorName ="";
        string authorEmail ="";
        string authorTwitterUsername ="";
    
        if (Model.MacroParameters["authorEmail"] != null)
        {
            authorEmail = (string)Model.MacroParameters["authorEmail"];
            var authorModel = Member.GetByEmail(authorEmail);
    
            authorName = member.getProperty("Name").Value;
            authorTwitterUsername = member.getProperty("TwitterUsername").Value;
        }
        }   
    
    Contact the author: @authorEmail or @authorTwitterUsername

    However, could not get it to work as intendend. 

  • Ole Kristian Losvik 22 posts 73 karma points
    Feb 21, 2015 @ 19:15
    Ole Kristian Losvik
    2

    Solved. In case anybody interested in an authorbio macro:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using System.Web.Mvc.Html
    @using ClientDependency.Core.Mvc
    @using Umbraco.Web
    @using Umbraco.Web.Controllers
    @using Umbraco.Core
    @using Umbraco.Core.Models
    @using Umbraco.Core.Services
    
        @{
        string authorName ="";
        string authorEmail ="";
        string authorCity ="";
        string authorOccupation ="";
        string authorTwitterUsername ="";
        string authorProfilePage ="";
        string authorEmailHash ="";
        string authorImage = "";
    
        if (Model.MacroParameters["authorEmail"] != null)
        {
            authorEmail = (string)Model.MacroParameters["authorEmail"];
            var authorModel = Members.GetByEmail(authorEmail);
            authorName = authorModel.Name.ToString();
            authorTwitterUsername = (string)authorModel.GetProperty("twitterUsername").Value;
            authorEmailHash = Umbraco.CreateMd5Hash(authorEmail);
            authorImage = "http://www.gravatar.com/avatar/" + authorEmailHash + ".jpg?s=70";
            authorCity = (string)authorModel.GetProperty("city").Value;
            authorOccupation = (string)authorModel.GetProperty("occupation").Value;
            authorTwitterUsername =(string)authorModel.GetProperty("twitterUsername").Value;
            authorProfilePage =(string)authorModel.GetProperty("profilePage").Value;
        }
        }       
    
    <div xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Person" class="author-bio">
      <div class="author-photo" property="v:photo">
         <img src="@authorImage" class="photo author-photo">
      </div>
      <div class="author-info">
         <p class="author-title">Av <span property="v:name" class="fn">@authorName</span></h3>
         <p class="author-description"<span property="v:title">@authorOccupation</span>. 
           <span rel="v:address">@authorCity</span>. 
         </p>
         <p class="author-links"><a href="@authorProfilePage" rel="v:url">Forfatterside</a> p&aring; <span property="v:affiliation">helselosen.no</span>
         </p>
    </div>
    </div>
    
    <style>
    .author-bio {background: #9ec6d7; padding: 0px; margin: 5px; width: 100%; height:auto; overflow:auto;}
    .author-photo {float: left; padding: 0px; margin: 0px; height:70px; width:70px;}
    .author-info {float: left; height:70px; padding: 7px;}
    .author-title {color:#323740; font-size: 1.3rem; margin:0px; }
    .author-description {color:#323740;font-size: 1.3rem; margin:0px; }
    .author-links {color:#323740;font-size: 1.3rem; margin:0px;}
    .author-links a {color:#323740; text-decoration:underline;}
    </style>
    
  • Proxicode 127 posts 323 karma points
    Jul 01, 2016 @ 19:58
    Proxicode
    0

    Thank you Ole :-)

Please Sign in or register to post replies

Write your reply to:

Draft