Snippets
Snippets are reusable page fragments that can be embedded in multiple pages. They allow you to define a widget tree once and include it wherever needed, promoting consistency and reducing duplication.
CREATE SNIPPET
CREATE [OR REPLACE] SNIPPET <Module>.<Name>
(
[Params: { $Param: Module.Entity [, ...] },]
[Folder: '<path>']
)
{
<widget-tree>
}
Basic Snippet
A snippet without parameters:
CREATE SNIPPET MyModule.Footer
(
Folder: 'Snippets'
)
{
CONTAINER cFooter (Class: 'app-footer') {
DYNAMICTEXT txtCopyright (Content: '2024 My Company. All rights reserved.')
}
}
Snippet with Parameters
Snippets can accept entity parameters, similar to pages:
CREATE SNIPPET MyModule.CustomerCard
(
Params: { $Customer: MyModule.Customer }
)
{
CONTAINER cCard (Class: 'card') {
DATAVIEW dvCustomer (DataSource: $Customer) {
DYNAMICTEXT txtName (Content: '{1}', Attribute: Name)
DYNAMICTEXT txtEmail (Content: '{1}', Attribute: Email)
ACTIONBUTTON btnEdit (
Caption: 'Edit',
Action: PAGE MyModule.Customer_Edit,
ButtonStyle: Primary
)
}
}
}
Using Snippets in Pages
Embed a snippet in a page using the SNIPPETCALL widget:
CREATE PAGE MyModule.Home
(
Title: 'Home',
Layout: Atlas_Core.Atlas_Default
)
{
CONTAINER cMain {
SNIPPETCALL scFooter (Snippet: MyModule.Footer)
}
}
Inspecting Snippets
-- List all snippets in a module
SHOW SNIPPETS IN MyModule;
-- View full MDL definition
DESCRIBE SNIPPET MyModule.CustomerCard;
DROP SNIPPET
DROP SNIPPET MyModule.Footer;
ALTER SNIPPET
Snippets support the same in-place modification operations as pages. See ALTER PAGE / ALTER SNIPPET:
ALTER SNIPPET MyModule.CustomerCard {
SET Caption = 'View Details' ON btnEdit;
INSERT AFTER txtEmail {
DYNAMICTEXT txtPhone (Content: '{1}', Attribute: Phone)
}
};
See Also
- Pages – page overview
- Widget Types – available widgets including SNIPPETCALL
- ALTER PAGE – modifying snippets and pages in-place
- Common Patterns – patterns that use snippets