Once you create a custom field associated to a particular content type, content editors can enter information in this field while creating content of this type in the backend. For more information, see Custom fields.
To display the custom field and the information it represents on the frontend of your website, you need to add the field to the widget template that you use to display that content type. For example, if you have a custom field Country in your News module, you need to add the Country field to News widget template. Widget templates are located in the MVC/Views folder of the resource package your website is using. For more information, see Resource packages.
Custom fields for built-in modules work the same way as the fields of dynamic modules since dynamic modules are comprised entirely of custom fields. Once you create a dynamic content type, a List and a Detail view templates for this content type are generated under Design » Widget templates. These templates consist of HTML markup and Razor code that renders the content of the custom field. For each type of custom field, for example, short text, long text, related data, and so on, there is a default custom field template. You use these templates to visualize the custom fields on the templates of built-in and dynamic widgets.
You can find all default custom fields templates in Default custom fields templates.
Once you create a custom field for a content type, the field is accessible via the model of the content widget. Thus, to add the custom field to this widget’s template, you reference the field through the Fields property of the Item, for example @Model.Item.Fields.Country. Depending on the type of field you created, you add the default custom field template, listed in Default custom fields templates. The following sample demonstrates how to add a Country custom field to a News module.
In the code above:
Sometimes you want to change the default custom field template, so that each time a widget template for a dynamic content type is generated, a custom field is rendered with a particular markup. For example, you want to customize the template of the ShortTextField custom field, so that it has a specific markup whenever you use in any content widget template.
Say you want to change the date format that the Date custom field uses. To do this:
DateTime
Тhis way the next time you generate a dynamic content type that contains a Date field, the template for this field will be pulled from your project, as opposed to taking the template from Sitefinity.
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important