Find a value on a page that has been picked with content picker
I am migrating over a card element that worked fine on Umbraco 7, but am having trouble in Umbraco 9. Essentially I have a Macro for a card that uses the content picker to select a URL. Once I have the URL, I grab the featured image from that page and use it as the image for the card. I was able to get access to this value in Umbraco 7 with no issues, but I have given this a run for the better half of a week now and I cannot find a suitable solution. Below is the code with a few different cracks at it (commented out). I can't seem to get back the URL for the featured image of the page that is being selected though. Can anyone figure out what the issue might be? It is much appreciated.
@inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage
@{
var linkTo = Umbraco.Content(Model.MacroParameters["cardIntURL"]);
@* This attempt got Error loading partial view *@
@* var getFeaturedImg = Umbraco.TypedMedia(linkTo.GetPropertyValue("featuredImage")).Url; *@
@* This attempt got Error loading partial view *@
@* var getFeaturedImg = Umbraco.Media(linkTo.GetPropertyValue("featuredImage")); *@
@* Card renders with no value for variable *@
@* var getFeaturedImg = Umbraco.Media(linkTo.Value("featuredImage")); *@
@* Card renders with the value being "Umbraco.Cms.Core.Models.MediaWithCrops`1[Umbraco.Cms.Infrastructure.PublishedCache.PublishedContent]" *@
@* var getFeaturedImg = linkTo.Value("featuredImage"); *@
@* Card renders with no value for variable *@
var getFeaturedImg = Umbraco.Media(linkTo.HasValue("featuredImage"));
}
@if (linkTo!=null){
@* Passing variables in p tags just to see what gets returned *@
<p>@linkTo.Url()</p>
<p>@getFeaturedImg</p>
<div class="cds-card-blog cds-rounded cds-shadow-hover">
<img class="cds-card-blog-img-top img-fluid card-img-top w-100 d-block" src="/media/oo0bsuxx/staffing-trends-2022.jpg">
<div class="cds-card-blog-body">
<a class="cds-card-blog-header" href="@linkTo.Url()">
<h3 class="cds-text-journey cds-mt-0">@Html.Raw( @Model.MacroParameters["cardIntTitle"] )</h3>
</a>
<p>@Html.Raw( @Model.MacroParameters["cardIntContent"] )</p>
<a class="cds-card-blog-link" href="@linkTo.Url()">@Model.MacroParameters["cardIntBtnText"]</a>
</div>
</div>
}
Find a value on a page that has been picked with content picker
I am migrating over a card element that worked fine on Umbraco 7, but am having trouble in Umbraco 9. Essentially I have a Macro for a card that uses the content picker to select a URL. Once I have the URL, I grab the featured image from that page and use it as the image for the card. I was able to get access to this value in Umbraco 7 with no issues, but I have given this a run for the better half of a week now and I cannot find a suitable solution. Below is the code with a few different cracks at it (commented out). I can't seem to get back the URL for the featured image of the page that is being selected though. Can anyone figure out what the issue might be? It is much appreciated.
For anybody else running into this issue - I was able to figure it out using the code below:
is working on a reply...