Sitecore Content Hub - Using Transformations on our Sitecore site
Transformations are a very important (and often ignored) feature, it basically lets you crop images on the fly and set the quality of images, without the need of creating custom public links. This is Sitecore's documentation related to Content Hub Transformations, however, how do we actually use these from a Sitecore site?
The short answer is you can't use Transformations using the Sitecore Connect for Content Hub connector. I have talked to Sitecore Support and they added a feature request so that public links inserted from the connector support transformations (reference number 518659).
In the meantime, what we can do, is add the transformations programmatically (I know, it's not the best) but if we want to leverage Content Hub Transformations on our Sitecore sites that's the only thing we can do for now. Sitecore support recommended using something like this in code:
Sitecore.Data.Fields.XmlField imageField = Sitecore.Context.Item.Fields["image"];
string src = imageField.GetAttribute("src") + "&t=mytransformation";
Then we would be able to use the src as our img src.
@if (Model.MediaImage.IsContentHubContent)
{
<img src="@(Model.MediaImage.GetContentHubTransformationSrc("TransformationNameGoesHere"))" alt="@(Model.MediaImage.Alt)" />
}
Comments
Post a Comment