Rendering Images in Content Areas

Vote:
 

Hi,

Not sure how to map the default view for an image that has been added to a Content Area. Pre 12 version the default view was possible to be added under ~/Views/Shared/DisplayTemplates/Image.cshtml.

Trying my luck currently with Template Coordinator with no luck so far. Any hints and ideas would be appreciated.

Thanks,

#297701
Mar 04, 2023 17:33
Vote:
 

Got this working with Template Coordinator - or IViewTemplateModelRegistrator, but don't think that it is the correct and most straight forward way.

For those who would be interested in this - added a registration for content of type ImageData and passed the data to a view like:

            viewTemplateModelRegistrator.Add(typeof(ImageData), new TemplateModel
            {
                Name = "Image",
                Inherit = true,
                AvailableWithoutTag = true,
                Path = DisplayTemplatesPath("Image.cshtml")
            });

Used the ImageData.Content link to extract the url etc..

Any other way of processing this would be appreciated.

Thank you,

#297702
Mar 04, 2023 17:49
Vote:
 

Seems a valid solution although an alternate suggestion would be to use an PartialContentComponent, example from Alloy 

/// <summary>
/// Controller for the image file.
/// </summary>
public class ImageFileViewComponent : PartialContentComponent<ImageFile>
{
    private readonly UrlResolver _urlResolver;

    public ImageFileViewComponent(UrlResolver urlResolver)
    {
        _urlResolver = urlResolver;
    }

    /// <summary>
    /// The index action for the image file. Creates the view model and renders the view.
    /// </summary>
    /// <param name="currentContent">The current image file.</param>
    protected override IViewComponentResult InvokeComponent(ImageFile currentContent)
    {
        var model = new ImageViewModel
        {
            Url = _urlResolver.GetUrl(currentContent.ContentLink),
            Name = currentContent.Name,
            Copyright = currentContent.Copyright
        };

        return View(model);
    }
#297785
Mar 06, 2023 0:08
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.