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> [FOLDER '<path>']
[(
Params: ( $Param: Module.Entity [, ...] )
)]
{
<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: SHOW 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)
}
};
A snippet with parameters takes its arguments in Params:, one Param = $variable
each. The variable is a parameter of the calling page, or — for a call inside
another snippet — a parameter of that snippet. A parameter the enclosing data
context satisfies is left out:
SNIPPETCALL scCard (Snippet: MyModule.CustomerCard, Params: (Customer = $Customer))
DESCRIBE prints the arguments in this form, so a snippet call keeps its
mappings through describe and exec.
Inspecting Snippets
-- List all snippets in a module
LIST 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)
};
INSERT INTO ctnActions { -- append as the container's last child
ACTIONBUTTON btnMore (Caption: 'More', Action: NOTHING)
}
};
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