I would like to display an image from content type "A" inside content type "B". This involves checking if content type "A" does not have an image before displaying image from content type "B". Can anyone help please?
it does depend a bit on how you are finding Content Type 'A" in your code. but as an example - if we assume you have some form of content picker on your content node that lets the user pick content type 'a' from b:
// get the content ID from the current page (Content "B")
var contentId = Model.GetPropertyValue<int>("contentPicker");
// get the content Node
var contentNode = Umbraco.TypedContent(contentId);
if (contentNode != null)
{
// check the property is there and has a value
if (contentNode.HasProperty("image") && contentNode.HasValue("image"))
{
var imgId = contentNode.GetPropertyValue<int>("image");
var img = Umbraco.TypedMedia(imgId);
if (img != null)
{
// you have the image here...
<img src="@img.Url" />
}
}
}
assuming :
"contentPicker" is a property on the content item where the user picks the content with the image
Displaying image from different content type
I would like to display an image from content type "A" inside content type "B". This involves checking if content type "A" does not have an image before displaying image from content type "B". Can anyone help please?
Hi
it does depend a bit on how you are finding Content Type 'A" in your code. but as an example - if we assume you have some form of content picker on your content node that lets the user pick content type 'a' from b:
assuming :
is working on a reply...