Copied to clipboard

Flag this post as spam?

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


  • Bent Holz 100 posts 273 karma points
    Apr 06, 2018 @ 11:36
    Bent Holz
    0

    Alt title to image media type

    I have added a property (seoTitle) to my image data type, so that I can add seo titles to images I upload.

    Now I would like to display this title but I cant get it to work.

        @{
        var mediaGet1 = Model.Content.GetPropertyValue<IPublishedContent>("aboutUsPicture");
        var seoTitle = Model.Content.GetPropertyValue<IPublishedContent>("seoTitle");
        if (mediaGet1 != null)
        {
            <img src="@mediaGet1.Url" alt="@seoTitle"/>                 
        }
    }
    

    I thought it would be straight forward but this only displays the image, but not the alt title...

    Any suggestions?

    Cheers!

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 06, 2018 @ 11:48
    Dave Woestenborghs
    102

    Hi Bent,

    I think the problem is you are getting the seo title from the content item instead of the image. Can you try this :

    @{
        var mediaGet1 = Model.Content.GetPropertyValue<IPublishedContent>("aboutUsPicture");
        var seoTitle = mediaGet1.GetPropertyValue<string>("seoTitle");
        if (mediaGet1 != null)
        {
            <img src="@mediaGet1.Url" alt="@seoTitle"/>                 
        }
    }
    

    Dave

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 09, 2018 @ 07:08
    Michaël Vanbrabandt
    0

    Hi Bent,

    did you solved your issue using the answer of @Dave? Could you share it with the community?

    Have a nice day!

    /Michaël

  • Bent Holz 100 posts 273 karma points
    Apr 09, 2018 @ 08:31
    Bent Holz
    1

    It absolutely worked and makes perfect sence!... Just had the weekend off ;)

    Cheers Dave, thank you!...

Please Sign in or register to post replies

Write your reply to:

Draft