Developer forum

Forum » Templates » Razor image metadata title

Razor image metadata title

Martin Kure
Reply

When working with a gallery, you can use this tag <!--@Gallery.Image.Metadata.title--> to retrieve the metadata, added to the image.

But is there a way you can retrieve the same data from an item, that loops through the content of a folder. I would like to use the metadata.title of the image as caption text in a gallery, but can't seem to find a way.

Here's the code:

foreach(var file in GetLoop("Item.Mappe.ListOfFiles")){
            var imgPath =folder + "/" + file.GetValue("Item.Mappe.FileName");
            <a href="/admin/public/getimage.ashx?Image=@imgPath&Resolution=72&Compression=90&Width=1000&Height=600&Crop=0"
          class="strip"
          data-strip-group="mygroup" data-strip-caption="[HERE I WOULD LIKE TO USE THE METADATA]"><div class="col-lg-4 col-sm-4 col-md-4 stripjs__padding"><img src="/admin/public/getimage.ashx?Image=@imgPath&Resolution=72&Compression=90&Width=300&Height=350&Crop=0" class="img-responsive"></div></a>
        }

 

BR

Martin

 


Replies

 
Sten Hougaard
Reply

Hi Martin,

I am not sure where the image metadata in Dynamicweb is stored. If it is in a database table you should be able to get the information using either the API, otherwise you can do a SQL query to retrieve the data.

If the meta data is stored in the image, you will need to access the image using .NET file system class. That however is a slow task (file system access always is), and you should be careful about doing that.

A third solution could be to handle it through the item, either extending the item to hold the image meta data, manually adding the information as you create or edit the item. Another approach might be to go for the code based item types which Dynamicweb supports. I personally have only played a little around with that way of using items, and never in production environments.

In short what you could then do was to let the code based item fetch the metadata each time the item is saved. I know that Morten Bengtson from Bleau have previously commented on related posts here, so perhaps Morten could share his points of view on this subject.

A little history 

Many years back I suggested tag extensions in Dynamicweb like the Price tag extensions, that could extract EXIF picture meta data, so that might just also be a solution on this issue (if data is stored inside the images as EXIF meta data). Writing your own tag extensions actually is easy in Dynamicweb.

I actually wrote a blog post about just that: first Dynamicweb Tag Extension

 

/Sten Hougaard

@netsi1964

For hire: http://www.netsi.dk/CV2006.htm 

 
Nicolai Høeg Pedersen
Reply

You can do like this in Razor:

Meta m = EditorFactory.GetMetadataForFile(path);
m.GetValue("fieldname");
 
Martin Kure
Reply

Hi Nicolai, 

Have used your code like so:

    foreach(var file in GetLoop("Item.Mappe.ListOfFiles")){
            Meta m = EditorFactory.GetMetadataForFile(path);
            var metacontent = m.GetValue("title");
            var imgPath =folder + "/" + file.GetValue("Item.Mappe.FileName");
            <a href="/admin/public/getimage.ashx?Image=@imgPath&Resolution=72&Compression=90&Width=1000&Height=600&Crop=0"
          class="strip"
          data-strip-group="mygroup" data-strip-caption="@metacontent"><div class="col-lg-4 col-sm-4 col-md-4 stripjs__padding"><img src="/admin/public/getimage.ashx?Image=@imgPath&Resolution=72&Compression=90&Width=300&Height=350&Crop=0" class="img-responsive"></div></a>
        }

get the following errors:

Line 9: The name 'EditorFactory' does not exist in the current context
Line 9: The type or namespace name 'Meta' could not be found (are you missing a using directive or an assembly reference?)
Line 9: The name 'EditorFactory' does not exist in the current context
Line 9: The name 'path' does not exist in the current context

 

 
Nicolai Høeg Pedersen
Reply

Sorry, Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(path); is the full name.
And the path has to be a valid path of course... That would be a mappath of your imgPath variable.

 

You must be logged in to post in the forum