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 there
I'm trying to create a marquee with a list of items, that should be displayed on all pages. My struture
WIthin each chillditem there's a mediapicker with marqueeLogo and a textfiled with marqueeLogoAlt How I tried to accomplish this:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var selection = CurrentPage.Site().Kunder.Children.Where("Visible"); } <ul> @foreach (var id in selection) { var item = Umbraco.Content(id); var marqueeItem = Umbraco.Media(@item.marqueeLogo); <li class="slideItem"> <img src="@marqueeItem.umbracoFile" alt='@item.marqueeLogoAlt'/> </div> </li> } </ul>
I'm guessing that it's my selection variable that doesn't point correct. Also tried root.Kunder.Children and root.Descendents("Kunder")
I'm pretty new to the new Umbraco, so not really sure how to point it correctly, so they will be shown on all pages.
Thanks in advance Henrik
Hi Henrik,
I don't recommend you to use CurrentPage object and other dynamic helpers, especially if you just started to work with Umbraco, it will be better for you to start from strongly typed approach.
I rewrite your macro like that:
@inherits Umbraco.Web.Mvc.UmbracoViewPage @{ var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.Name == "Kunder"); } <ul> @foreach (var item in kunderSection.Children) { var marqueeItem = Umbraco.TypedMedia(item.GetPropertyValue("marqueeLogo")); <li class="slideItem"> <img src="@marqueeItem.Url" alt="@marqueeItem.GetPropertyValue("marqueeLogoAlt")" /> </li> } </ul>
1) Inheriting from UmbracoViewPage gives you strongly typed model of view without dynamics
2) Please change this line - var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.Name == "Kunder");
I used selection by name, because don't know doctype of Kunder node, better will be use it like :
var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "KunderDocumentTypeAlias");
3) Do you want to create macro for using it in all site? You have to use
@inherits Umbraco.Web.Macros.PartialViewMacroPage
And place your macro view in ~/Views/MacroPartials, read more https://our.umbraco.org/documentation/reference/templating/macros/partial-view-macros/
I hope it will help you, write if something.
Thanks,
Alex
Hi Alex and thank you very much for your informative suggestion.
I tried creating a macro instead called ClientMarquee which is located in ~/Views/MacroPartials/ClientMarquee.cshtml
I'm using the code from your suggestion, but when trying to render the macro I get this:
Error loading Partial View script (file: ~/Views/MacroPartials/ClientMarquee.cshtml)
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "Kunder"); } <ul> @foreach (var item in kunderSection.Children) { var marqueeItem = Umbraco.TypedMedia(item.GetPropertyValue("marqueeLogo")); <li class="slideItem"> <img src="@marqueeItem.Url" alt='@marqueeItem.GetPropertyValue("marqueeLogoAlt")' /> </li> } </ul>
The docType is Kunder as you assumed, so not sure where I'm going wrong.
Henrik
1) Added few checks for null, now code looks like:
@{ var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "Kunder"); } @if (kunderSection != null) { <ul> @foreach (var item in kunderSection.Children) { var marqueeItem = Umbraco.TypedMedia(item.GetPropertyValue("marqueeLogo")); if (marqueeItem != null) { <li class="slideItem"> <img src="@marqueeItem.Url" alt='@marqueeItem.GetPropertyValue("marqueeLogoAlt")'/> </li> } } </ul> }
2) Also be carefull with DocumentTypeAlias, check it, it's often lowercase so maybe document type alias is "kunder" and you need to change to
x.DocumentTypeAlias == "kunder"
Please check in your Umbraco.
Hi again Alex
Now it's working perfectly.
Thanks you very, very much for your help!
I really appreciate it
Best Henrik
Maybe problem with @marqueeItem.GetPropertyValue("marqueeLogoAlt")
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "Kunder"); } @if (kunderSection != null) { <ul> @foreach (var item in kunderSection.Children) { var marqueeItem = Umbraco.TypedMedia(item.GetPropertyValue("marqueeLogo")); if (marqueeItem != null) { string altText = string.Empty; if (marqueeItem.HasValue("marqueeLogoAlt")) { altText = marqueeItem.GetPropertyValue<string>("marqueeLogoAlt"); } <li class="slideItem"> <img src="@marqueeItem.Url" alt="@altText"/> </li> } } </ul> }
Added check for altText property.
You are welcome !!! I'm glad to help.
Best,
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
List items from specific node globally
Hi there
I'm trying to create a marquee with a list of items, that should be displayed on all pages.
My struture
WIthin each chillditem there's a mediapicker with marqueeLogo and a textfiled with marqueeLogoAlt
How I tried to accomplish this:
I'm guessing that it's my selection variable that doesn't point correct.
Also tried root.Kunder.Children and root.Descendents("Kunder")
I'm pretty new to the new Umbraco, so not really sure how to point it correctly, so they will be shown on all pages.
Thanks in advance
Henrik
Hi Henrik,
I don't recommend you to use CurrentPage object and other dynamic helpers, especially if you just started to work with Umbraco, it will be better for you to start from strongly typed approach.
I rewrite your macro like that:
1) Inheriting from UmbracoViewPage gives you strongly typed model of view without dynamics
2) Please change this line - var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.Name == "Kunder");
I used selection by name, because don't know doctype of Kunder node, better will be use it like :
3) Do you want to create macro for using it in all site? You have to use
And place your macro view in ~/Views/MacroPartials, read more https://our.umbraco.org/documentation/reference/templating/macros/partial-view-macros/
I hope it will help you, write if something.
Thanks,
Alex
Hi Alex and thank you very much for your informative suggestion.
I tried creating a macro instead called ClientMarquee which is located in ~/Views/MacroPartials/ClientMarquee.cshtml
I'm using the code from your suggestion, but when trying to render the macro I get this:
The docType is Kunder as you assumed, so not sure where I'm going wrong.
Henrik
Hi Henrik,
1) Added few checks for null, now code looks like:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
2) Also be carefull with DocumentTypeAlias, check it, it's often lowercase so maybe document type alias is "kunder" and you need to change to
Please check in your Umbraco.
Thanks,
Alex
Hi again Alex
Now it's working perfectly.
Thanks you very, very much for your help!
I really appreciate it
Best
Henrik
Maybe problem with @marqueeItem.GetPropertyValue("marqueeLogoAlt")
Added check for altText property.
Thanks,
Alex
You are welcome !!! I'm glad to help.
Best,
Alex
is working on a reply...