Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martin Rud 258 posts 989 karma points c-trib
    May 05, 2022 @ 03:57
    Martin Rud
    0

    uMazel: How to hook into methods SrcSetManager() and CreatePictureElement()

    Hi forum,

    I have just taken over on an customers Umbraco project from another Umbraco partner. The partner has implemented the Umbraco site (Umbraco v. 8.12.2) site using uMazel (v. 2.0.0).

    I need know to hook into the methods SrcSetManager() and CreatePictureElement() to alter image paths (add CDN prefix), css classes and more...:

    <picture>
        <source media="only screen and (min-width: 1200px)" srcset="/media/nztauqwu/my-image.jpg?center=x,y&amp;mode=crop&amp;quality=70&amp;width=550">
        <source media="only screen and (min-width: 992px)" srcset="/media/nztauqwu/my-image.jpg?center=x,y&amp;mode=crop&amp;quality=70&amp;width=435">
        <source media="only screen and (min-width: 768px)" srcset="/media/nztauqwu/my-image.jpg?center=x,y&amp;mode=crop&amp;quality=70&amp;width=325">
        <source media="only screen and (min-width: 576px)" srcset="/media/nztauqwu/my-image.jpg?center=x,y&amp;mode=crop&amp;quality=70&amp;width=450">
        <source media="only screen and (min-width: 1px)" srcset="/media/nztauqwu/my-image.jpg?center=x,y&amp;mode=crop&amp;quality=70&amp;width=450">
        <img src="/media/nztauqwu/my-image.jpg" alt="My alt text" class="myClass">
    </picture>
    

    ... in for instance the view Views\Partials\SectionBlocks\Cached\SectionImageTextBlock.cshtml:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Core.Models.Blocks.BlockListItem>
    
    @using Site.Core;
    @using Site.Core.ViewModels;
    @using DotSee.Common;
    @using DotSee.ResponsiveImages;
    @using DotSee.Common;
    @using System.Text;
    
    @{
        SectionImageTextBlock currSection = Model.Content as SectionImageTextBlock;
        SectionImageTextBlockSettings settings = Model.Settings as SectionImageTextBlockSettings;
    
        SrcSetManager ssm = new SrcSetManager(currSection.Image, "sectionImageText");
    
        string cssClass = Utils.ConcatCssClasses(
            new string[] {
            settings.GetSectionPtb()
            , settings.GetSectionMtb()
        });
    
        string cssClassText = (currSection.ImageLeftSide) ? "col-sm-push-6" : null;
        string cssClassImage = (currSection.ImageLeftSide) ? "col-sm-pull-6" : null;
    
    }
    
    <section id="[email protected]()" class="imageText @cssClass">
    
        <div class="container">
    
            <div class="row">
                <div class="text mb-sm-15 col-xs-12 col-sm-6 @cssClassText">
                    <h3>@currSection.SectionTitle</h3>
                    <div class="text">@currSection.Text</div>
                </div>
                <div class="image mb-sm-15 col-xs-12 col-sm-6 @cssClassImage">
                    @ssm.CreatePictureElement(imageAlt: currSection.SectionTitle)
                </div>
            </div>
        </div>
    </section>
    

    But when I go ti the methods definitions, I just end up here ("SrcSetManager (from metadata)") and canĀ“t go further:

    using System.Collections.Generic;
    using System.Web;
    using Umbraco.Core.Models.PublishedContent;
    
    namespace DotSee.ResponsiveImages
    {
        public class SrcSetManager
        {
            public SrcSetManager(IPublishedContent originalImage, string ruleSetName, Dictionary<int, IPublishedContent> altImages = null);
    
            public void AddAltImage(int maxWidth, IPublishedContent image);
            public IHtmlString CreateMarkup(string alt = "", string title = "", string srcSetAttrName = "srcset", Dictionary<string, string> otherAttributes = null);
            public IHtmlString CreatePictureElement(string imageAlt = "", string imageClass = "", Dictionary<string, string> imageAttributes = null);
            public IHtmlString GetBreakPointsCss();
            public string GetClassName();
            public IHtmlString GetSizes();
            public IHtmlString GetSrcSet();
        }
    }
    

    How can I hook into the methods?

  • Sotiris Filippidis 286 posts 1501 karma points
    May 05, 2022 @ 17:13
    Sotiris Filippidis
    100

    uMazel author here. Short answer - right now you can't. :(

    All methods imply that you're using an IPublishedContent item (i.e. a Media item). I haven't tested stuff with external URLs, but I suspect that ImageProcessor won't work well with those.

    Unfortunately we're not providing source code for this at the moment.

  • Martin Rud 258 posts 989 karma points c-trib
    May 05, 2022 @ 20:30
    Martin Rud
    0

    Thanks for the info. :)

Please Sign in or register to post replies

Write your reply to:

Draft