Developer forum

Forum » Templates » How to retrieve Metatags set on image

How to retrieve Metatags set on image

Christian Hansen Nørgaard
Reply

Hi DW.

Like the title says, how do I retrieve Metatags set on images? I found a tag that I could use if I am on a Product page: @GetString("Ecom:Product.Imagepackshot.Metadata.Alt") - In my product catalog I am using alt. images where my prefix is packshot - but how can I retrieve the same data on e.g. checkout, or on an image used in my master.cshtml, or an image used in a paragraph?

Regards,

Christian


Replies

 
Nicolai Pedersen
Reply

Hi Christian

You can use the files.metadata api: http://doc.dynamicweb.com/api/html/941fdba2-bbe0-0a9b-1f0c-7f7b71cbd6fe.htm

BR Nicolai

 
Christian Hansen Nørgaard
Reply

Hi Nicolai.

Had to look around a bit more but found a solution in the end using your post.

Adding my solution for others to use in e.g. paragraphs, notice I am using 2 language layers:

    string imgpath = "/Files/Images/ProductImages/" + imagename;
    var m = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(imgpath);
    var metacontent = "";
    var lang = GetGlobalValue("Global:Area.Lang");
    if (lang == "da")
    {
        metacontent = m.GetValue("Alt");
    }
    else if (lang == "en")
    {
        metacontent = m.GetValue("AltEng");
    }

Now use the variable in an img: <img src="" alt="@metacontent" />

 
Nicolai Pedersen
Reply

Great, thanks for sharing!

 

You must be logged in to post in the forum