Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Halsey 59 posts 220 karma points
    Mar 19, 2014 @ 13:09
    John Halsey
    0

    How to display 1 specific image in Media if a certain doc type is selected

    I'm creating a small repository for products. I'm giving the user the ability to select a "Coming Soon" product. I have set up a specific "ComingSoon" doc type and there is an image in the media library that I want to display every time this doc type is used. How can I do that? I can display the image of "actual products" without any problems.

    Here is my code so far

     @{var categories = Model.Children;
        foreach(var subpage in categories)
        {
                        @if (subpage.NodeTypeAlias == "ComingSoon")
                        {
                            var defaultImage = Library.MediaById(1175);
                            <img src="@Library.MediaById(1175)" alt="@defaultImage.altText" />
                        }
                        else
                        {
                            <a href="@subpage.Url">
                            <img src="@subpage.Media("mainImage", "umbracoFile")" alt="@subpage.Media("mainImage", "altText")" />
                            </a>
                        }
        }
        }
    

    Thanks

  • John Halsey 59 posts 220 karma points
    Mar 19, 2014 @ 13:18
    John Halsey
    100

    Actually I seem to have figured this out.

    I just change this

    <img src="@Library.MediaById(1175)" alt="@defaultImage.altText" />
    

    to this

    <img src="@Library.MediaById(1175).umbracoFile" alt="@Library.MediaById(1175).altText" />
    

    Yay me!

Please Sign in or register to post replies

Write your reply to:

Draft