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
Hello,
I've written the below code to look up a root node that has child nodes which pulls out banner images with a caption. Now i can get the page name and URL out fine, i'm now having trouble getting the image out.
@inherits Umbraco.Web.Macros.PartialViewMacroPage <div class="bannersContainer"> @foreach (var childBanner in Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("BannersIndex"))) { <div class="carousel slide" data-ride="carousel" data-pause="false"> @if (childBanner.Children.Any(x => x.DocumentTypeAlias.Equals("Banner"))) { <div class="carousel-inner"> @foreach (var banner in childBanner.Children.Where(p => p.DocumentTypeAlias.Equals("Banner"))) { <div class="item"> <a href="@banner.Url">@banner.Name</a> <img class="bannerImg" src="@Umbraco.TypedMedia("bannerImage").Url" /> </div> } </div> } </div> } </div>
Using @Umbraco.TypedMedia("bannerImage").Url doesn't seem to do the trick.
@Umbraco.TypedMedia("bannerImage").Url
Any ideas as to what i should be using here?
Hi Mohammad,
What if you do something like this does it work then.
@inherits Umbraco.Web.Macros.PartialViewMacroPage<div class="bannersContainer"> @foreach (var childBanner in Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("BannersIndex"))) { <div class="carousel slide" data-ride="carousel" data-pause="false"> @if (childBanner.Children.Any(x => x.DocumentTypeAlias.Equals("Banner"))) { <div class="carousel-inner"> @foreach (var banner in childBanner.Children.Where(p => p.DocumentTypeAlias.Equals("Banner"))) { <div class="item"> <a href="@banner.Url">@banner.Name</a> @{ if(banner.HasValue("bannerImage")){ var mediaItem = Umbraco.TypedMedia(banner.GetPropertyValue("bannerImage")); <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")"/> } } </div> } </div> } </div> }</div>
Hope this helps,
/Dennis
Hi Mohammad
Have you tried just writing @Umbraco.TypedMedia("bannerImage").umbracoFile
@Umbraco.TypedMedia("bannerImage").umbracoFile
Hope this helps.
/Jan
Hi Dennis,
That worked a treat! Need to remember "GetPropertyValue" it just wouldn't drop in to my head.
Jan, you're solution didnt work, something do with there is no definite .umbracoFile for iPublishedContent
Cheer's guys, just need to now figure why carousel isnt showing the image - ha!
Many Thanks Javed
Hi Javed
Aaah, yes - Was not thinking straight there :)
Good you got it working though.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
IPublishedContent - How To Render Image (Razor)?
Hello,
I've written the below code to look up a root node that has child nodes which pulls out banner images with a caption. Now i can get the page name and URL out fine, i'm now having trouble getting the image out.
Using
@Umbraco.TypedMedia("bannerImage").Url
doesn't seem to do the trick.Any ideas as to what i should be using here?
Hi Mohammad,
What if you do something like this does it work then.
Hope this helps,
/Dennis
Hi Mohammad
Have you tried just writing
@Umbraco.TypedMedia("bannerImage").umbracoFile
Hope this helps.
/Jan
Hi Dennis,
That worked a treat! Need to remember "GetPropertyValue" it just wouldn't drop in to my head.
Jan, you're solution didnt work, something do with there is no definite .umbracoFile for iPublishedContent
Cheer's guys, just need to now figure why carousel isnt showing the image - ha!
Many Thanks Javed
Hi Javed
Aaah, yes - Was not thinking straight there :)
Good you got it working though.
/Jan
is working on a reply...