Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi guys
I've been working on a blog on our company website.
When adding a blogpost, I want to print the name and image (custom property) from the member who wrote the post.
I can print the name, but the custom image property (upload) doesn't do anything.
My code so far looks like this
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var blogPosts = Umbraco.TypedContentAtXPath("//blogpost").OrderBy("UpdateDate desc").Take(5); } @{ <ul class="blogCats"> @foreach (var item in blogPosts) { var teaserBanner = Umbraco.TypedMedia(item.GetPropertyValue("blogTeaserBanner")); var member = Umbraco.TypedMember(item.GetPropertyValue<int>("author")); if((teaserBanner != null) && (member != null)) { <li class="blogPost"> <div class="blogPostImg"> <img src="@teaserBanner.Url" alt="" /> <p class='postLabel @item.Parent.Name.ToString().ToLower().Replace("æ", "ae").Replace("ø", "oe").Replace("å", "aa").Replace(" ", "")'>@item.Parent.Name</p> </div> <div class="postedByWrapper"> <div class="postedBy"> <img src="@member.memberImage.Url" /> <p>@member.Name | <span><i class="fa fa-calendar"></i></span><span class="date">@item.UpdateDate.ToString("dd/MM/yyyy")</span></p> </div> </div> <h2 class="postHeader">@item.GetPropertyValue("blogOverskrift")</h2> <div class="postTeaser">@item.GetPropertyValue("blogPostTeaser")</div> <a class="blogReadMore" href="@item.Url">Læs artiklen</a> </li> } } </ul> }
I tried making an extra var for the image and did an if statement check down in the code, but that failed horribly :D
Hope you guys can give me a push in the right direction.
Thank you in advance
Best
Henrik
Hi Henrik
Try this code:
@member.GetPropertyValue("memberImage")
It should print our member image url
Thanks,
Alex
Thank you very much Alex!
Worked like a charm :)
Have a great week
Hi again
So I got it working with Alex's solution, but I need to call it on specific categories as well, to only call the blogposts of a specific category.
When doing that I get the following error:
'Umbraco.Web.PublishedContentModels.Member' does not contain a definition for 'GetPropertyValue'
My only change from the original code example is the following:
@{ var selection = CurrentPage.Children.Where("Visible"); }
I'm guessing the error lies in, that it can't connect to the member service now.
Tried adding
using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Services;
but doesnt make any difference.
Do you have any idea how to solve this, so that I don't have to make a view for each category.
This code returns dynamic typed results:
Do not use dynamic types, try to use this code:
var selection = Umbraco.AssignedContentItem.Children.Where(x => x.IsVisible());
Awesome, Alex!
You're the man!
Haven't seen Umbraco.AssignedContentItem before, but worked perfectly.
Is it correct that CurrentPage is in it's own "scope", and therefor can't access other services?
Whereas Umbraco. is global and therefor can access the memberservice etc?
"Umbraco.AssignedContentItem" is a current page, use it everywhere in views.
"CurrentPage" is the same as Umbraco.AssignedContentItem, but dynamic type.
"Umbraco" is a helper for accessing Umbraco data.
Alright.
Thanks a lot for taking time to clarify :)
Have a great day.
You are welcome, Henrik! Have a nice day too.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Fetching custom Member properties in view
Hi guys
I've been working on a blog on our company website.
When adding a blogpost, I want to print the name and image (custom property) from the member who wrote the post.
I can print the name, but the custom image property (upload) doesn't do anything.
My code so far looks like this
I tried making an extra var for the image and did an if statement check down in the code, but that failed horribly :D
Hope you guys can give me a push in the right direction.
Thank you in advance
Best
Henrik
Hi Henrik
Try this code:
It should print our member image url
Thanks,
Alex
Thank you very much Alex!
Worked like a charm :)
Have a great week
Best
Henrik
Hi again
So I got it working with Alex's solution, but I need to call it on specific categories as well, to only call the blogposts of a specific category.
When doing that I get the following error:
'Umbraco.Web.PublishedContentModels.Member' does not contain a definition for 'GetPropertyValue'
My only change from the original code example is the following:
I'm guessing the error lies in, that it can't connect to the member service now.
Tried adding
but doesnt make any difference.
Do you have any idea how to solve this, so that I don't have to make a view for each category.
Thank you in advance
Best
Henrik
Hi Henrik
This code returns dynamic typed results:
Do not use dynamic types, try to use this code:
Thanks,
Alex
Awesome, Alex!
You're the man!
Haven't seen Umbraco.AssignedContentItem before, but worked perfectly.
Is it correct that CurrentPage is in it's own "scope", and therefor can't access other services?
Whereas Umbraco. is global and therefor can access the memberservice etc?
"Umbraco.AssignedContentItem" is a current page, use it everywhere in views.
Is it correct that CurrentPage is in it's own "scope", and therefor can't access other services?
"CurrentPage" is the same as Umbraco.AssignedContentItem, but dynamic type.
"Umbraco" is a helper for accessing Umbraco data.
Thanks,
Alex
Alright.
Thanks a lot for taking time to clarify :)
Have a great day.
Best
Henrik
You are welcome, Henrik! Have a nice day too.
Thanks,
Alex
is working on a reply...