Create custom page attributes
IMPORTANT: This article documents functionality that is no longer the recommended approach when adding dynamic fields to pages. The information below it is available for migration purposes only, in case you were using custom page attributes in Sitefinity CMS versions prior to 7.0, when custom fields for pages were introduced. To follow the officially recommended approach, check the Add custom fields to pages article.
Custom fields of modules in Sitefinity CMS is a widely used feature. You can extend built-in modules by adding various types of fields to the data stored in these modules. This feature comes with Custom page attributes. The following article explains how you can use them.
NOTE: Backend pages and group pages do not support custom fields.
Creating a custom page attribute
You create custom page attributes through configuration, and you can only use the user interface for it. To create a new custom attribute, perform the following:
- In the main menu, click Administration » Settings » Advanced
- In the tree view on the left, click ContentView » Controls » FrontendPages » Views
- To edit the view for creating pages, click FrontendPagesCreate and perform the following:
- To open the section where your custom attribute will appear, click Sections »AdvancedOptionsSection » Fields.
NOTE: You can also choose any other section, not only Advanced Options.
- To create the attribute, click Create New.
- From the list that appears, choose TextFieldDefinitionElement.
NOTE: You can also choose other types of attributes, such as ChoiceFieldElement, HierarchicalTaxonFieldDefinitionElement, and FlatTaxonFieldDefinitionElement.
- In the DataFieldName textbox, enter the name of the persistent field where you want to store the value of the attribute. This name must be prefixed with Attributes. This is a convention Sitefinity CMS uses to distinguish custom page attributes from the rest. If you want your field to be named DemoField, then enter Attributes.DemoField.
- In the FieldName textbox, enter the name of the field without any prefix.
- In the FieldDefinitionTitleCaption textbox, enter the Title of the field. This value appears in the user interface, while the Name value is used by the system.
- Click Save Changes.
- To edit the view for editing pages, click FrontendPagesEdit.
- To create the attribute in the edit view, perform again Step 3a to Step 3f and use the same field name and title.
- Click Save Changes.
Editing the value of a custom page attribute
Once you have created a custom page attribute, you can edit its value when creating or editing a page. For information about creating a custom attribute, see Creating a custom page attribute earlier in this article.
To edit the value of an attribute, perform the following:
- In the main menu, click Pages.
- If you want to set an attribute when creating a new page, click Create a page.
- Enter a title for the page. For more information, see Edit and delete a page.
- Expand the section where you created the custom attribute. For example, expand the Advanced options section.
The custom attribute that you created appears in the section. Depending on the type you selected, there may be different user interface for editing the value. If you selected TextFieldDefinitionElement, a textbox appears.
- In the textbox, enter the value for your custom attribute.
- Click Create and go to add content.
- Click Publish.