0

Will or should Sitecore automatically sanitize field names when serialising them as part of the layout service or do we need ensure we define fields in Sitecore using a consistent format?

e.g. would "Page Title" be serialised to pageTitle.

  • Somewhat related: a good practice to reduce complications is to ensure field names have no spaces. For content author readability, you can add the spaces in the "Title" field of the field item (think of it like the display name for content authors). Utilizing the "Title" field also decreases the likelihood of having to rename fields down the line which can break your application if you haven't accounted for that possibility. – Marcel May 26 at 17:33
0

Layout service will not do anything with the field names when responding to any item request, you will be seeing field name in JSON response. It's basically our design to define an appropriate name(s) for fields. As per your ex- if you created a field with name "Page Title" then it will be returned as "Page Title".

Layout Service will only serialize field values and return appropriately. Each and every field type is having it's own serialization logic to return value in Layout service JSON.

For ex -

If you have "Single-Line-Text" field "pageTitle", value will be "pageTitle":{"value":"Welcome to Sitecore JSS"}

If you have an image field, value will be something similar to this, image":{"value":{"src":"https://example.com/-/media/img/apple-logo.ashx?h=550&w=800","alt":"","width":"800","height":"550"}}

You can see all serialization logics for all field types in this config \App_Config\Sitecore\LayoutService\Sitecore.LayoutService.config

<getFieldSerializer performanceCritical="true">
            <processor type="Sitecore.LayoutService.Serialization.Pipelines.GetFieldSerializer.GetImageFieldSerializer, Sitecore.LayoutService" resolve="true">
              <FieldTypes hint="list">
                <fieldType id="1">image</fieldType>
              </FieldTypes>
            </processor>
          ......
</getFieldSerializer>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.