I know I'm missing something blindingly obvious but my brain just isn't playing ball today.I want to do a simple if statement with an AND operator. I'm doing a test to see if the page has an image. If it does, I want to display a smaller banner. If it doesn't have an image selected, I want to make the banner the full width. I'm doing this with a variable named 'bannersize'.
It seems like I'm not testing for the variable's value correctly as the result is a YSOD. Any help would be much appreciated!
Thanks,
Tom
@{
var bannersize = "small";
if(Model.Content.HasValue("logoImage")){ var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("logoImage"));
I was just using the variable to choose what to render.
The user has the option to pick a couple of images. If they pick an image for slot 1 and 2, I need to make them a bit smaller. If they pick just slot 2, it will fill up the space used slot 1 and 2 sit in. I figured the easiest way was to check if slot 1 was filled and if not, to make slot 2 bigger.
Do you think this would be better achieved with a case rather than an if statement? It just seems a little odd that I can create a variable but not use it in my if statement unless the contents are rendered somewhere?
Good point. I was overcomplicating things in my head!
Cheers Dennis.
One thing that's still baffling me slightly though is why I couldn't test against a variable unless it is dropped into the page. Is that a razor thing or an Umbraco thing or just the way I was approaching it?
Quick variable test
Hey,
I know I'm missing something blindingly obvious but my brain just isn't playing ball today.I want to do a simple if statement with an AND operator. I'm doing a test to see if the page has an image. If it does, I want to display a smaller banner. If it doesn't have an image selected, I want to make the banner the full width. I'm doing this with a variable named 'bannersize'.
It seems like I'm not testing for the variable's value correctly as the result is a YSOD. Any help would be much appreciated!
Thanks,
Tom
Hi Tom,
I just had a look into your code, and I think I have corrected your code so it will works.
Try to use this code below instead and see if it works like intended.
Hope this helps,
/Dennis
It works, but the @bannersize then displays the value of the variable in the page as plain text..?
Does it need to be rendered as part of the page for Umbraco to use the variable? If it does, I guess I can hide it with css.
Hi Tom,
Just to be sure what do you need the large and small banner variable for, then I am sure we can find a way of doing it :-)
/Dennis
I was just using the variable to choose what to render.
The user has the option to pick a couple of images. If they pick an image for slot 1 and 2, I need to make them a bit smaller. If they pick just slot 2, it will fill up the space used slot 1 and 2 sit in. I figured the easiest way was to check if slot 1 was filled and if not, to make slot 2 bigger.
Do you think this would be better achieved with a case rather than an if statement? It just seems a little odd that I can create a variable but not use it in my if statement unless the contents are rendered somewhere?
Thanks for the quick response by the way!
Hi Tom,
Okay so if they pick an image for slot 1 and 2, you need to make them a bit smaller. I was thinking if you then just could do something like this.
So you check of if slot 1 and 2 then you have pictures in one size else then you can set another width and height
Hope this helps,
/Dennis
Good point. I was overcomplicating things in my head!
Cheers Dennis.
One thing that's still baffling me slightly though is why I couldn't test against a variable unless it is dropped into the page. Is that a razor thing or an Umbraco thing or just the way I was approaching it?
Hi Tom,
You can also do this. I think that you could use the code below.
Hope this helps, and make sense.
/Dennis
So if I went back to my original post and added in a double equals, it would have worked?
Sorry - didn't even notice you'd added that into the second post! Long day.
Thanks for all your help.
Hi Tom,
Yes I think so, but beware that you need to make two variables, therefor I have changed the names to
And then you can test against this with double equals,
/Dennis
is working on a reply...