Add additional scoping variables to Responsive Image Variants definition.

Robert Srigley asked on May 23, 2018 20:54

What is the proper syntax to add another scope (site,pagetype,path) to the image variant definitions which are located in my /CMS/App_Code/Demo/ResponsiveImages/Definitions/ folder.

The current sysntax is ~~~

public override IEnumerable<IVariantContextScope> ContextScopes
        {
            get
            {
                return new[] {
                    new AttachmentVariantContextScope()
                        .OnSite("DancingGoat")
                        .Type("DancingGoat.Article")
                        .Path("/Articles")
                };
            }
        }

I want to add a new .OnSite("Connect"), .Type("Connect.Informed"), .Path("/Informed")

Do I append it to the existing definition, or add a new AttachmentVariantContextScope() code block.

Thank you

Correct Answer

Michael Eustace answered on May 31, 2018 13:10

Hi Robert,

This is covered in the documentation here, but for convenience, this is how it can be achieved:

public override IEnumerable<IVariantContextScope> ContextScopes
{
    get
    {
        return new[]
        {
            new AttachmentVariantContextScope().OnSite("DancingGoat")
                .Type("DancingGoat.Article")
                .Path("/Articles", PathTypeEnum.Children),

            new AttachmentVariantContextScope().OnSite("CorporateSite")
                .Type("CMS.News")
                .Path("/News", PathTypeEnum.Children)
        };
    }
}

Best regards, Michael

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.