Hi - I'm trying to use an altFieldAlias inside GetPropertyValue, but it doesn't seem to be falling back properly. The primary alias works fine, and the secondary alias for the altFieldAlias works in a secondary loop, so maybe its my syntax? Here's the edited down code:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.WShome>
@using ContentModels = Umbraco.Web.PublishedContentModels;
var homeLayout = CurrentPage.homepageLayout;
var promoSpots = 0;
var sortedPosts = CurrentPage.Site().FirstChild("wSHome").Children("article").Where("Visible").OrderBy("Promoted desc, CreateDate desc");
@foreach (var post in sortedPosts.Take(promoSpots))
{
<img src="@Umbraco.Media(post.GetPropertyValue("promotionImage", altFieldAlias: "articlePreviewImage")).GetCropUrl("thumb")" alt="@Umbraco.Media(post.GetPropertyValue("promotionImage", altFieldAlias: "articlePreviewImage")).altText" />
}
@foreach (var post in sortedPosts.Skip(promoSpots).Take(6))
{
<img src="@Umbraco.Media(post.GetPropertyValue("articlePreviewImage")).GetCropUrl("thumb")" alt="@Umbraco.Media(post.GetPropertyValue("articlePreviewImage")).altText" />
}
I'm new to Umbraco so thanks in advance for any help or tips!
To help you, i just need a little more info. What datatype is promotionImage and articlePreviewImage?
Image Cropper, Media Picker?
Looking at the IPublishedContent properties i cant see that the GetPropertyValue(string) method has a altFieldAlias parameter. Maybe you are confusing it with the UmbracoHelper method @Umbraco.Field(string, altFieldAlias = string)? You can probobly use the GetPropertyValue(string) by first checking if promotionImage has value with the method @post.HasValue(string propertyAlias).
Have i understood you correct that you´d like the first loop to render the posts images for the property promotionImageIF it has a value, otherwise fallback and render the image for property articlePreviewImage?
With a little more info i´d be happy to help and probobly be able to show some code samples.
Hi Dennis - thanks so much for your response! I think you're correct that I'm trying to use GetPropertyValue() like @Umbraco.Field's altFieldAlias helper, so that won't probably work.
As for the datatype, they are both using Media Picker.
Have i understood you correct that you´d like the first loop to render
the posts images for the property promotionImage IF it has a value,
otherwise fallback and render the image for property
articlePreviewImage?
Yes! Exactly..
So I think I want to do something like this:
@foreach (var post in sortedPosts.Take(promoSpots))
{
var postImg = post.promotionImage;
if (post.HasValue("promotionImage") == false)
{
postImg = post.articlePreviewImage;
}
<div class="post">
<img src="@Umbraco.Media(post.GetPropertyValue(postImg)).GetCropUrl("thumb")" alt="@Umbraco.Media(post.GetPropertyValue("promotionImage", altFieldAlias: "articlePreviewImage")).altText" />
<p class="intro">@post.GetPropertyValue("headline")</p>
</div>
}
But I'm getting an ambiguous call error..
The call is ambiguous between the following methods or properties:
'Umbraco.Web.UmbracoHelper.Media(params int[])' and
'Umbraco.Web.UmbracoHelper.Media(params string[])'
You get a ambiguous call becaus it's possible to pass both a string and a int to the Umbraco.Media() method. And you are trying to pass in a type object.
Since you are using a mediapicker you won't have to use GetPropertyValue() since postImg will be a number.
altFieldAlias in GetPropertyValue
Hi - I'm trying to use an altFieldAlias inside GetPropertyValue, but it doesn't seem to be falling back properly. The primary alias works fine, and the secondary alias for the altFieldAlias works in a secondary loop, so maybe its my syntax? Here's the edited down code:
I'm new to Umbraco so thanks in advance for any help or tips!
Hi phaedra.
To help you, i just need a little more info. What datatype is
promotionImage
andarticlePreviewImage
? Image Cropper, Media Picker?Looking at the IPublishedContent properties i cant see that the
GetPropertyValue(string)
method has a altFieldAlias parameter. Maybe you are confusing it with the UmbracoHelper method@Umbraco.Field(string, altFieldAlias = string)
? You can probobly use the GetPropertyValue(string) by first checking if promotionImage has value with the method@post.HasValue(string propertyAlias)
.IPublishedContent Properties: https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/Properties
Umbraco Helper: https://our.umbraco.org/documentation/reference/Templating/Mvc/views
Have i understood you correct that you´d like the first loop to render the posts images for the property
promotionImage
IF it has a value, otherwise fallback and render the image for propertyarticlePreviewImage
?With a little more info i´d be happy to help and probobly be able to show some code samples.
All the best / Dennis
Hi Dennis - thanks so much for your response! I think you're correct that I'm trying to use GetPropertyValue() like @Umbraco.Field's altFieldAlias helper, so that won't probably work.
As for the datatype, they are both using Media Picker.
Yes! Exactly..
So I think I want to do something like this:
But I'm getting an ambiguous call error..
Any thoughts? And thanks again!!
You get a ambiguous call becaus it's possible to pass both a string and a int to the Umbraco.Media() method. And you are trying to pass in a type object.
Since you are using a mediapicker you won't have to use GetPropertyValue() since postImg will be a number.
Try:
Umbraco.Media(postImg.ToString())
That totally worked & so much cleaner - thank you!!
One last question: when you said
where are you looking to find out the properties? I'm having trouble finding the documentation.
Awesome to hear that it worked out for you!! :) Happy I could help!!
Here is the documentation for IPublishedContent: https://our.umbraco.org/documentation/reference/querying/ipublishedcontent/
All the best! / Dennis
Awesome - so helpful! Thanks again!
is working on a reply...