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 new to umbraco and razor and am trying to get an banner image to display on each page.
The banner image should be the banner image on the page if it has one otherwise should be the next banner image it finds up the content tree.
E.g
Homepage - has banner
Section One -has no banner so should pick up from homepage
Section Two - has banner should display it's own
subsection two - has no banner should pick up banner from Section Two not homepage.
Section Three - has no banner should pick up from homepage
subsection three - has no banner should pick up from Homepage
etc
The code I have so far is
@{
var bannerImage = Model.Content.AncestorsOrSelf().Where(x => x.HasProperty("bannerImage") && x.HasValue("bannerImage")).FirstOrDefault();
if (bannerImage != null){
<img class="banner" src="@(bannerImage.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("bannerImage").First.Url)"/>
}
but this either gives me the first banner image on every page
Any help much appreciated
Bal
Hi,
You can create a recursive method, something like this:
@functions{//To place in .cshtml
public static string GetPath(int nodeId)
{
var m = uQuery.GetNode(nodeId);
string res = string.Empty;
if (true)//check if has property and value
res = "";//n.prop.value;
}else
{//call it again and send its parent id
res = GetPath(m.Parent.Id);
return res;
Hi Balram,
I wonder, could you try the following?
var bannerImage = Model.Content.AncestorOrSelf().Where(x => x.HasProperty("bannerImage") && x.HasValue("bannerImage"));
Jeavon
Hi Jeavon
That's done the trick thanks very much
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Banner Image won't work recursively
HI
I'm new to umbraco and razor and am trying to get an banner image to display on each page.
The banner image should be the banner image on the page if it has one otherwise should be the next banner image it finds up the content tree.
E.g
Homepage - has banner
Section One -has no banner so should pick up from homepage
Section Two - has banner should display it's own
subsection two - has no banner should pick up banner from Section Two not homepage.
Section Three - has no banner should pick up from homepage
subsection three - has no banner should pick up from Homepage
etc
The code I have so far is
@{
var bannerImage = Model.Content.AncestorsOrSelf().Where(x => x.HasProperty("bannerImage") && x.HasValue("bannerImage")).FirstOrDefault();
if (bannerImage != null){
<img class="banner" src="@(bannerImage.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("bannerImage").First.Url)"/>
}
}
but this either gives me the first banner image on every page
Any help much appreciated
Bal
Hi,
You can create a recursive method, something like this:
@functions{//To place in .cshtml
public static string GetPath(int nodeId)
{
var m = uQuery.GetNode(nodeId);
string res = string.Empty;
if (true)//check if has property and value
{
res = "";//n.prop.value;
}else
{//call it again and send its parent id
res = GetPath(m.Parent.Id);
}
return res;
}
}
Hi Balram,
I wonder, could you try the following?
Jeavon
Hi Jeavon
That's done the trick thanks very much
Bal
is working on a reply...