Figure: ALT Attribute - Author: Seobility - License: CC BY-SA 4.0Author: Seobility - License: CC BY-SA 4.0Optimizely CMS 12 offers out the box integration with Optimizely DAM allowing users to easily select images from the DAM. Its also possible to access the meta data for these assets such as the alt text.

One of the most common requests I hear is "How do I access the alt text for the image". Implementors can render alt text to a page using ASP.net MVC or HTML or tag helpers as described here: Caching & Rendering of metadata from the DAM. However many developers just want to grab the alt text to put into their own view models or even use directly in the view.

This post describes a helper I put together to help implementors get the alt text for an image from Optimizely DAM using Optimizely CMS 12. The code for the helper allows users to pass a content reference and will return a string containing the alt text of the image as configured in Optimizely CMP.

Implementation

Steps to implement:

  1. Install the DAM asset picker: CMP DAM Asset Picker in CMS 
  2. Configure the integration: Configure the Optimizely CMP integration 
  3. Add this code to your solution (Gist): Optimizely DAM alt text helper for Optimizely CMS 12
  4. Ensure IDamAltTextHelper is configured in Startup.cs (as described in the step above)

Once installed its then possible to pass the content reference to the GetAltText method to retrieve the alt text. The final result is that implementors can then access the alt text directly using a single helper method:

Once installed its then possible to pass the content reference to the GetAltText method to retrieve the alt text using a single helper method.

Useful links

Disclaimer

This code is provided as-is and it's purpose is to provide an example to implementors.


Comments

Recommendations for you