More dufus problems: ImageGen displays 'Hello World!' when no image exists. I have a doctype laid out for articles with ~15 images, but not all images will be included in every article so I need to just skip the ones that aren't there.
The following shows me the image ID but doesn't skip it if there's no value for 'picId'. Using any other operator aside from != null throws an 'Error loading MacroEngine script'.
@{ var pic = @Parameter.figure; var picId = @Model.GetProperty(pic); if (picId != null) { <a href="@Library.MediaById(Model.GetPropertyValue(pic)).umbracoFile"> <img src="/imagegen.ashx?width=550&[email protected](Model.GetPropertyValue(pic)).umbracoFile" alt="" /> </a> } }
I've tried everything I can find about checking images but still not getting it.
Or, if there's a better way to approach the problem, I'm open.
When there is an image, it shows the image and: pic = fig1 picId = 1214 media =
When there's not, it's 'Hello World!' and: pic = fig1 picId = media =
Based on picId returning a number if there's an image, I thought I had already got the image ID, and was just tripping over not knowing what is the correct way of testing for the empty picId. Should there be some kind of Int32 or string conversion in there? Looks like a number when it's a number but seems like it's not if it's not.
check if image exists
More dufus problems: ImageGen displays 'Hello World!' when no image exists. I have a doctype laid out for articles with ~15 images, but not all images will be included in every article so I need to just skip the ones that aren't there.
The following shows me the image ID but doesn't skip it if there's no value for 'picId'. Using any other operator aside from != null throws an 'Error loading MacroEngine script'.
I've tried everything I can find about checking images but still not getting it.
Or, if there's a better way to approach the problem, I'm open.
Yeah, just check to see if the media node's id is 0, like so:
Thanks for the quick reply Douglas, and the var media refinement. Is that mostly to clean up my sloppy guesswork image tags?
Unfortunately, using your code as is still throws the 'Error loading MacroEngine script', so I wonder if I've pooched something elsewhere.
If I strip it down (use my old image tags instead of yours, kill the 'if') and toss in:
When there is an image, it shows the image and:
pic = fig1
picId = 1214
media =
When there's not, it's 'Hello World!' and:
pic = fig1
picId =
media =
Based on picId returning a number if there's an image, I thought I had already got the image ID, and was just tripping over not knowing what is the correct way of testing for the empty picId. Should there be some kind of Int32 or string conversion in there? Looks like a number when it's a number but seems like it's not if it's not.
Also, if I add in media.Id:
It throws the same error.
Sorry, this should work:
Model.GetProperty(string alias) returns an IProperty object. You can then access the value with .Value (if it's not null, obviously).
Awesome! Very much appreciated, and thanks for the explanation. I will study up on those refinements.
is working on a reply...