Page Tag Helpers and slots
Add your own content inside a page of the admin panel
StellarAdmin renders the content of each resource page with a Tag Helper. When you override a page, your view uses the Tag Helper for the page, and passes it the view's model:
| Tag Helper | Page | Model |
|---|---|---|
<sa-index-page> | Index | ResourceIndexPageViewModel<TResource> or IResourceIndexPageViewModel |
<sa-form-page> | Create and edit | ResourceFormPageViewModel |
<sa-view-page> | View | ResourceViewPageViewModel |
@model ResourceViewPageViewModel
@{
ViewData["Title"] = Model.Title;
}
<sa-view-page model="Model" />Adding content with slots
A slot is a place inside the page where you can add your own content, such as a button in the page's header. To fill a slot, put an <sa-slot-content> element with the slot's name inside the Tag Helper.
The example below adds an Invoice button after the Edit button of the bookings view page, and a card below the fields:
@model ResourceViewPageViewModel
@{
ViewData["Title"] = Model.Title;
}
<sa-view-page model="Model">
<sa-slot-content name="post-page-actions">
<sa-link-button href="@($"/invoices/{Model.EntityId}")" variant="ButtonVariant.Outline">
Invoice
</sa-link-button>
</sa-slot-content>
<sa-slot-content name="post-view-fields">
<sa-card>
<sa-card-content>Payment history goes here.</sa-card-content>
</sa-card>
</sa-slot-content>
</sa-view-page>The Tag Helper renders only the content of its <sa-slot-content> elements. Anything else you put inside it isn't rendered. To add content outside the slots, put it before or after the Tag Helper.
Each Tag Helper has the following slots:
| Tag Helper | Slot | Where the content goes |
|---|---|---|
<sa-index-page> | pre-page-actions | In the header, before the Create button |
post-page-actions | In the header, after the Create button | |
<sa-form-page> | pre-form-fields | Above the fields |
post-form-fields | Below the fields | |
form-leading-actions | In the header, at the start of the form's buttons | |
pre-form-actions | In the header, before the Cancel button | |
post-form-actions | In the header, after the submit button | |
<sa-view-page> | pre-page-actions | In the header, at the start of the page's buttons |
post-page-actions | In the header, after the Edit button | |
pre-view-fields | Above the fields | |
post-view-fields | Below the fields |
The edit page has no Delete button. To add one, see adding a Delete button to the edit page.
The index page has no slot between its header and the grid. To add content there, put it above the Tag Helper, as in the example on overriding pages.
Replacing the content of the page
To replace the content that a Tag Helper renders, set its view attribute to the name of your own partial view, or to its path from your app's root. The partial view receives the Tag Helper's model, and renders the content of a slot where it contains an <sa-slot-outlet> element with the slot's name:
<sa-slot-outlet name="post-page-actions" />