JSSでのカスタムレイアウトサービス設定の使用
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
Layout ServiceのJSONレンダリング プロセスは高度に構成可能であり、Layout Serviceの特定の側面をカスタマイズできます。
jss Layout Service構成の任意の要素をカスタマイズする場合は、ref属性を使用して既存の構成をコピーし、その要素内でカスタマイズすることをお勧めします。これにより、アップグレード中にjss構成が変更された場合に、構成に必要な変更を減らすことができます。
JSSで使用されるレイアウト サービス構成を変更すると、オブジェクトの形状、シリアル化、およびプレースホルダー処理が変更されると、JSS SDKが破損し、JSSインポート プロセスによる想定と競合する可能性があります。
シリアル化設定を変更すると、ユーザーが影響を与えられないJSONデータを変更できます。シリアル化設定を変更するときは、JSON出力全体を変更することも、フィールド名のみを変更することもできます。たとえば、フィールド名をキャメルケースにする場合は、フィールド名を変更できます。
カスタム構成を定義したら、renderJsonRenderingパイプラインの<AllowedConfigurations>リストに構成名を追加します。これにより、デフォルトのjss設定で実行されるPlaceholderTransformerコードがカスタム設定に対しても実行されるようになります。
この手順は、カスタム構成がデフォルトのJSS構成と形状が類似した出力を提供する場合にのみ関連します。カスタム構成がJSSに関連していない場合、またはデフォルトのjss構成のいずれにも依存していない場合、この手順は必要ありません。
以下は、デフォルトのjss設定に基づくmy-jss-configという名前のカスタム レイアウト サービス設定のSitecore設定パッチです。
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<layoutService>
<configurations>
<!-- Define your custom named config, using the `ref` attribute to "copy" the existing `jss` configuration -->
<config name="my-jss-config">
<rendering ref="/sitecore/layoutService/configurations/config[@name='jss']/rendering">
<!-- Override placeholdersResolver -->
<placeholdersResolver type="My.Resolver, My.Assembly">
</rendering>
<serialization ref="/sitecore/layoutService/configurations/config[@name='jss']/serialization" />
</config>
</configurations>
</layoutService>
<pipelines>
<group groupName="layoutService">
<pipelines>
<renderJsonRendering>
<processor type="Sitecore.JavaScriptServices.ViewEngine.LayoutService.Pipelines.RenderJsonRendering.AddComponentName, Sitecore.JavaScriptServices.ViewEngine" resolve="true">
<AllowedConfigurations hint="list">
<!-- Custom named config is added to this list -->
<config id="2">my-jss-config</config>
</AllowedConfigurations>
</processor>
</renderJsonRendering>
</pipelines>
</group>
</pipelines>
</sitecore>
</configuration>
カスタム構成でパッチを適用した後、layoutServiceConfiguration属性を使用してJSSアプリケーションでその構成を利用できます。
<javaScriptServices>
<apps>
<app name="MyApp"
sitecorePath="/sitecore/content/MyApp"
layoutServiceConfiguration="my-jss-config"
inherits="defaults"
/>
</apps>
</javaScriptServices>
この設定名は、クライアントコードで指定する必要があるほか、dataApiを使用してレイアウトサービスを呼び出すときにも指定する必要があります(前の例を参照)。
レイアウトサービスの設定
レイアウト サービスの設定は、/sitecore/layoutService/configurationsパスのSitecore設定にあります。
<config name="jss">
<!--
An implementation of `Sitecore.LayoutService.Configuration.IRenderingConfiguration`.
Allows the addition of filtering logic to output renderings and placeholders.
-->
<rendering type="Sitecore.LayoutService.Configuration.DefaultRenderingConfiguration, Sitecore.LayoutService">
<!--
An implementation of `Sitecore.LayoutService.Placeholders.IPlaceholdersResolver`.
Extracts the exposed placeholders of a rendering. Also available is
`Sitecore.LayoutService.Placeholders.SimplePlaceholdersResolver`.
-->
<placeholdersResolver type="Sitecore.LayoutService.Placeholders.DynamicPlaceholdersResolver, Sitecore.LayoutService"/>
<!--
An implementation of `Sitecore.LayoutService.Serialization.ItemSerializers.IItemSerializer`.
Determines what fields of an item should be serialized and writes them out as JSON.
The default implementation filters standard fields. Also available is
`Sitecore.LayoutService.Serialization.ItemSerializers.AllFieldsItemSerializer`.
-->
<itemSerializer type="Sitecore.LayoutService.Serialization.ItemSerializers.DefaultItemSerializer, Sitecore.LayoutService" resolve="true"/>
<!--
An implementation of `Sitecore.LayoutService.ItemRendering.ContentsResolvers.IRenderingContentsResolver`.
This is the default contents resolver -- it can be overridden on a per-rendering basis, as described above.
-->
<renderingContentsResolver type="Sitecore.LayoutService.ItemRendering.ContentsResolvers.RenderingContentsResolver, Sitecore.LayoutService">
<IncludeServerUrlInMediaUrls>true</IncludeServerUrlInMediaUrls>
</renderingContentsResolver>
</rendering>
<!--
An implementation of Sitecore.LayoutService.Configuration.ISerializationConfiguration.
Controls the `JsonSerializerSettings` used by the Layout Service and any transformation of the resulting JSON.
The JSS `SerializationConfiguration` customizes JSON serialization to preserve the case of dictionary keys.
-->
<serialization type="Sitecore.JavaScriptServices.ViewEngine.LayoutService.SerializationConfiguration, Sitecore.JavaScriptServices.ViewEngine">
<!--
An implementation of `Sitecore.LayoutService.Serialization.ILayoutTransformer`.
Provides full control over the shape of the output JSON to optimize it for the use of specific client needs.
JSS optimizes the output for JavaScript consumption.
-->
<transformer type="Sitecore.JavaScriptServices.ViewEngine.LayoutService.Serialization.LayoutTransformer, Sitecore.JavaScriptServices.ViewEngine"/>
</serialization>
</config>
configノードのname属性は、レイアウトサービスURLのconfigパラメータに対応します。
/sitecore/api/layout/render/[config]?item=[path]&sc_lang=[language]&sc_apikey=[key]&tracking=[true|false]