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, I'm working on migrating my Umbraco 7.15.7 to 11.1
I tried to render the images without success. I looked in the documentation, forum, etc. but couldn't figure out.
Here's my code in 7.15.7:
It's a partial view macro file where first I'm getting the nodes for the section
var Imaging_node = Umbraco.Content(1234); var Imaging_pagesToList = @Imaging_node.Children.Where("Visible"); Imaging_pagesToList = Imaging_node.DescendantsOrSelf().Where("NodeTypeAlias == @0", "NewsPage");
Then I start display the images in few places, for example:
@if (Imaging_pagesToList.Last().HasValue("articleImg")) { <img src="@Umbraco.Media(Imaging_pagesToList.Last().articleImg.ToString()).Url" class="img-fluid" alt="@Imaging_pagesToList.Last().photoAlt" /> }
My questions are:
Question 1:
How can I get the nodes?
@Imaging_node.Children.Where("Visible")
and
DescendantsOrSelf().Where("NodeTypeAlias == @0", "NewsPage");
are not working and give me errors.
What I was able to do is the following , but I'm not sure if it's the right way:
var Imaging_pagesToList = @Imaging_node.Children.Where(x => x.IsVisible()); Imaging_pagesToList = Imaging_node.DescendantsOrSelf().OfTypes("NewsPage");
Question 2:
How do I render the images??
I tried many things, looked in the documentation, etc. and couldn't figure out.
This is (again) how I do it in my 7.15 website:
<img src="@Umbraco.Media(Imaging_pagesToList.Last().articleImg.ToString()).Url" class="img-fluid" alt="@Imaging_pagesToList.Last().photoAlt" />
where articleImg is a property in the document types that display the page. and photoAlt is a property to show the image description
Thanks for the help :)
Hi Meni,
Use this code:
var Imaging_pagesToList = @Imaging_node.Children.Where(n => n.IsVisible()); Imaging_pagesToList = Imaging_node.DescendantsOrSelf().Where(n => n.ContentType.Alias == "NewsPage");
Thanks, Alex
Thanks.
What about images? How do I render images in Umbraco 11?
Something like this:
<img src="@Umbraco.Media(Imaging_pagesToList.Last().Value<IPublishedContent>("articleImg").ToString()).Url()" class="img-fluid" alt="@Imaging_pagesToList.Last().Value("photoAlt")" />
Thanks, this works.
Quick question: I tried also this (before you answered me) and this is also works:
Imaging_pagesToList = Imaging_node.DescendantsOrSelf().OfTypes("NewsPage");
Is it also a correct way?
yes, but it's better to use strongly typed variables
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Migrate to Umbraco 11.1: How to get nodes, then render images (@Umbraco.Media)
Hi, I'm working on migrating my Umbraco 7.15.7 to 11.1
I tried to render the images without success. I looked in the documentation, forum, etc. but couldn't figure out.
Here's my code in 7.15.7:
It's a partial view macro file where first I'm getting the nodes for the section
Then I start display the images in few places, for example:
My questions are:
Question 1:
How can I get the nodes?
and
are not working and give me errors.
What I was able to do is the following , but I'm not sure if it's the right way:
Question 2:
How do I render the images??
I tried many things, looked in the documentation, etc. and couldn't figure out.
This is (again) how I do it in my 7.15 website:
where articleImg is a property in the document types that display the page. and photoAlt is a property to show the image description
Thanks for the help :)
Hi Meni,
Use this code:
Thanks, Alex
Thanks.
What about images? How do I render images in Umbraco 11?
Something like this:
Thanks, this works.
Quick question: I tried also this (before you answered me) and this is also works:
Is it also a correct way?
yes, but it's better to use strongly typed variables
is working on a reply...