1. レンダリング

レンダリングバリアントでのModelReferenceフィールドレンダラーの使用

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

SXAには、デフォルトのレンダリングと レンダリング バリアント ( Referenceフィールド レンダラーとModelフィールド レンダラーを含む) のセットが付属しています。ただし、型コレクションのモデル プロパティを処理するには、ModelReferenceフィールド レンダラーを使用する必要があります。

ModelReferenceフィールドレンダラーは、レンダリングモデル内の指定されたコレクションを反復処理し、追加のモデルフィールドレンダラーをサブアイテムとして使用してデータを抽出できるようにします。コレクションは、アイテムのPass through fieldフィールドで指定します。対象とするモデル コレクション プロパティは、IEnumerableインターフェイスを実装する必要があります。

Rendering variant structure diagram.

任意の標準フィールド レンダラーを、ModelReferenceフィールド レンダラーの下にネストして使用できます。また、次の図のProduct Bundle - Deprecatedに示すように、ModelReferenceフィールド レンダラーを、複数のレベルのネストされたオブジェクト (階層) を持つモデルのターゲット コレクション プロパティにネストすることもできます。

次のクラス図は、ModelReferenceフィールド レンダラーの使用方法の例を示しています。この図には、ModelReferenceレンダラーを使用して製品バンドル コンポーネントの既定のレンダリング バリアントを反復処理するための4つのネストされたコレクションがあります。

  • ProductBundleRenderingModelは、LineItemsコレクションを反復処理します。

  • ProductVariantクラスは、VariantSelectionsコレクションを反復処理します。

  • BundleVariantsReferenceは、ValidProductVariantsコレクションを反復処理します。

  • Optionsクラスは、Optionsコレクションを反復処理します。

  • BundleValueVariantsReferenceは、Variantsコレクションを反復処理します。

Diagram of the Product Bundle Rendering Model

Scribanテンプレートを変更することで 、製品バンドルをカスタマイズ できます。

ModelReferenceレンダラーを使用するには、コレクション プロパティを使用してレンダリング モデル クラスを作成する必要があります。モデル・クラスは、VariantsRenderingModel.

using Sitecore.XA.Foundation.Variants.Abstractions.Models; 
namespace ProductList.Models 
{ 
    public class ProductListRenderingModel: VariantsRenderingModel 
    { 
        public ICollection<Product> Products { get; set; } 
    } 
} 

構成

ModelReferenceフィールド レンダラーをSitecore.Commerce.XA.Foundation.Common.config設定ファイルに登録するには、次のコード スニペットを使用します。

<sitecore> 
    <services> 
        <register                             serviceType="Sitecore.Commerce.XA.Foundation.Common.RenderingVariants.Services.ICollectionPropertyExtractor, Sitecore.Commerce.XA.Foundation.Common" implementationType="Sitecore.Commerce.XA.Foundation.Common.RenderingVariants.Services.CollectionPropertyExtractor, Sitecore.Commerce.XA.Foundation.Common" lifetime="Singleton"/> 
    </services> 

<parseVariantFields> 
    <processor type="Sitecore.Commerce.XA.Foundation.Common.RenderingVariants.ParseVariantFields.ParseModelReference, Sitecore.Commerce.XA.Foundation.Common" resolve="true" /> 
</parseVariantFields> 

<renderVariantField> 
    <processor type="Sitecore.Commerce.XA.Foundation.Common.Pipelines.RenderVariantField.RenderModelReference, Sitecore.Commerce.XA.Foundation.Common" resolve="true" /> 
</renderVariantField> 
</sitecore> 
この記事を改善するための提案がある場合は、 お知らせください!