Option
Option
Option holds the page settings of a content type. It names the field that acts as the entry title and sets whether the content type holds one entry or many. It also marks entries as web pages with a URL. Set it on ContentModelling.Options before you call Create or Update on a ContentType.
When to Use This Class: Use this class when you create a content type for web pages, or a single-entry content type such as a home page.
Conceptual Role: Acts as the data model that the SDK serializes under the options key of a content type.
Returns: Option. The page settings of a content type.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Title | string? | No | null | UID of the field that holds the entry title, for example title. Serialized as title. |
| SubTitle | List<string>? | No | null | UIDs of the fields that form the entry subtitle. Serialized as sub_title. |
| Singleton | bool | No | false | true makes the content type hold a single entry. Serialized as singleton. |
| IsPage | bool | No | false | true marks the entries as web pages. Serialized as is_page. |
| UrlPattern | string? | No | null | URL pattern of the entries, for example /:title. Serialized as url_pattern. |
| UrlPrefix | string? | No | null | Prefix added before the URL of each entry, for example /blog/. Serialized as url_prefix. |
Class-Level Notes
Values the SDK always sends.
- Singleton and IsPage are bool values. The SDK sends singleton and is_page in every request that has an Option, with false when you do not set them.
- The SDK leaves out Title, SubTitle, UrlPattern, and UrlPrefix when they are null.
- When you leave ContentModelling.Options as null, the request body has no options key.
Method Index
Option has no methods. Set its properties and assign the object to ContentModelling.Options, then pass the model to the Create method.
Class-Level Snippet
The snippet below creates a Blog Post content type whose entries are web pages under /blog/.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Fields;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ContentModelling model = new ContentModelling
{
Title = "Blog Post",
Uid = "blog_post",
Schema = new List<Field>
{
new TextboxField { DisplayName = "Title", Uid = "title", DataType = "text", Mandatory = true, Unique = true },
new TextboxField { DisplayName = "URL", Uid = "url", DataType = "text" }
},
Options = new Option
{
Title = "title",
SubTitle = new List<string> { "url" },
Singleton = false,
IsPage = true,
UrlPattern = "/:title",
UrlPrefix = "/blog/"
}
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ContentType().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse()["content_type"]?["options"]?.ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}