Creating inherited web parts
Web part inheritance allows you to create specialized web parts based on other web parts. Inherited web parts use the same code files as the original, but you can:
- Change the definitions of the web part properties
- Prepare custom layouts
To create an inherited web part:
- Open the Web parts application.
- Select the category where you want to place the web part.
- Click New web part.
- Select Inherit from an existing web part.
- Type a Display name for the inherited web part.
- Choose the parent web part through the Inherit from selector.
- Click Save.
Inherited web parts work like regular standalone web parts. The main difference is that inherited web parts have the Inherited from field showing the parent web part instead of the File name selector that specifies the source file.
Modify the properties of inherited web parts on the Properties tab.
You can:
- Set the Default value for properties
- Determine whether properties are visible in the web part configuration dialog (Display field in the editing form)
- Modify the appearance and behavior of properties
- Add additional properties
You cannot:
- Remove inherited properties
- Change the Field name, Field type or Field size of inherited properties
Tip: Click Reset field to revert all settings of a modified property back to the original state (the system copies the property settings from the parent web part).
When you add new instances of the web part to a page, the system pre-configures the properties according to the specified values.
Example - Creating an inherited web part for displaying news
The following example shows how to create a news list web part inherited from the Repeater web part. The news list displays news articles by default, without requiring any configuration of the web part properties.
Open the Web parts application.
Select the Listings and viewers category.
Click New web part.
Choose Inherit from an existing web part and enter the following values:
Display name: Custom news list
Inherit from: Listings and viewers -> Pages -> Repeater
Click Save.
On the General tab, check Skip initial configuration and click Save again.
Switch to the Properties tab of the newly created web part.
- Here you can see the properties of the parent web part and override their default values or other settings.
Set the default values for the Path property:
- Select Path in the list of fields.
- Type /% as the Default value.
- Click Save.
Repeat the previous step for the following properties and default values:
- ClassNames: cms.news
- OrderBy: NewsReleaseDate
- TransformationName: cms.news.preview
- SelectedItemTransformationName: cms.news.default
Tip: You can also customize the properties of the inherited web part by adding new fields.
Result
Now you can add the inherited web part to the site:
- Open the Pages application.
- Choose a page in the content tree.
- Switch to the Design tab.
- Add the Custom news list web part to the page.
The web part displays all news items from the site without requiring any additional configuration.
Note: After adding an instance of an inherited web part, users can set the properties to any other values. The default values only make it easier to add web parts with specialized functionality (without requiring any configuration).