日本語版
最新ニュース
企業

マルチサイトの選択したサイトに基づいて、表示ページ/ブロックサムネイル

で 前のブログ マルチサイトソリューションの現在のサイトに基づいて、ブロックまたはプロパティの可視性を制御する方法について説明しました。同じ手法を使用して、選択したサイトに基づいてCMS内のページとブロックの異なるサムネイルを表示して、コンテンツ著者がコンポーネントまたはページタイプを識別できるようにします。 私たちが持っていると仮定します SiteHelper からのヘルパークラス 前のブログ、wwwrootの下にフォルダー構造を作成できます。各サイトには、サムネイル画像を備えた独自のサブフォルダーがあり、サブフォルダー名は私たちのものと一致します。MySite 列挙値: これで、ブロックとページの属性を継承することができます ImageUrlAttribute。コンストラクターでは、サムネイルが利用できるサイトをリストします。 [AttributeUsage(AttributeTargets.Class)] public class ImageUrlSitesAttribute : ImageUrlAttribute { private readonly ISiteHelper _siteHelper; //root folder with our thumbnails private readonly string _basePath = "/icons/blocks/"; public Dictionary Paths { get; set;…

マルチサイトの選択したサイトに基づいて、表示ページ/ブロックサムネイル

1747432048
2025-05-16 11:50:00

前のブログ マルチサイトソリューションの現在のサイトに基づいて、ブロックまたはプロパティの可視性を制御する方法について説明しました。同じ手法を使用して、選択したサイトに基づいてCMS内のページとブロックの異なるサムネイルを表示して、コンテンツ著者がコンポーネントまたはページタイプを識別できるようにします。

私たちが持っていると仮定します SiteHelper からのヘルパークラス 前のブログ、wwwrootの下にフォルダー構造を作成できます。各サイトには、サムネイル画像を備えた独自のサブフォルダーがあり、サブフォルダー名は私たちのものと一致します。MySite 列挙値:

これで、ブロックとページの属性を継承することができます ImageUrlAttribute。コンストラクターでは、サムネイルが利用できるサイトをリストします。

    [AttributeUsage(AttributeTargets.Class)]
    public class ImageUrlSitesAttribute : ImageUrlAttribute
    {
        private readonly ISiteHelper _siteHelper;

        //root folder with our thumbnails
        private readonly string _basePath = "/icons/blocks/";

        public Dictionary Paths { get; set; }

        public override string Path
        {
            get
            {
                var currentSite = _siteHelper.GetCurrentSite(null);
                if (Paths.ContainsKey(currentSite))
                {
                    var currentPath = Paths[currentSite];
                    if (!string.IsNullOrWhiteSpace(currentPath))
                    {
                        return currentPath;
                    }
                }

                //default if not defined for site, we can place generic images in the _basePath folder
                return _basePath + base.Path;
            }
        }

        public ImageUrlSitesAttribute(string path, params MySite[] sites) : base(path)
        {
            _siteHelper = ServiceLocator.Current.GetService();
            Paths = new Dictionary();
            foreach (var site in sites)
            {
                var sitePath = System.IO.Path.Combine(_basePath, site.ToString().ToLower(), path);
                Paths.Add(site, sitePath);
            }
        }
    }

Pageクラスで属性を使用できます。

    [ContentType(
        DisplayName = "Generic Page",
        Description = "Standard page of an article.",
        GUID = "0AF06AF4-3185-4D8C-A65E-D942AC9A27D3")]
    [ImageUrlBrands("GenericPage.jpg", sites: new[] { MySite.Site1, MySite.Site2, MySite.Site3 })]
    public class GenericPage : PageData
    {
    }

またはブロッククラス:

    [ContentType(DisplayName = "Hero Full Screen",
        GUID = "A0C85434-35DE-42BF-88B7-1136B936AEAD",
        Description = "Display an immersive hero when the brand and/or hotel website pages load.",
        GroupName = GroupNames.Hero)]
    [ImageUrlBrands("HeroFullScreen.jpg", sites: new [] { MySite.Site1, MySite.Site2, MySite.Site3, MySite.Site4})]
    public class HeroFullScreenBlock : BlockData
    {
    }

著者がサイト1の下に新しいブロックを追加する場合、最終結果:

そしてサイト2の下:

2025年5月16日

#マルチサイトの選択したサイトに基づいて表示ページブロックサムネイル

執筆者について: nipponese

Nipponese News編集部は、国内外のニュースを日本語で分かりやすくお届けします。