Snippet Call
Introduction
The Snippet call widget allows you to use a snippet on a page, a layout, or another snippet:
Properties Pane
The properties pane is divided into two major sections by a toggle at the top of the pane: Properties and Styling. Snippet call properties consist of the following sections:
Properties:
Styling:
Properties
General Section
Snippet
The Snippet property shows the name of the snippet that the snippet call will display.
Snippet Settings
The Snippet settings property opens a dialog box that shows a list of parameters of the selected snippet and the arguments that will be passed to each of them. For more information, see Passing Arguments.
Common Section
Passing Arguments
An argument must be passed to every snippet parameter of the snippet that is called. The Snippet settings dialog box lists the parameters of the snippet with their Name, Type, and Argument.
To configure the argument of a parameter, select the parameter and click Edit parameter value. In the subsequent dialog box, set Type to either Variable or Expression. This works the same for object and primitive parameters.
In the example below, the snippet has an object parameter Order and a primitive parameter Amount of type Integer/Long. Both parameters have an argument:
Variable Arguments
Variable arguments are used to pass a value from the context of the snippet call to the snippet. Do this by selecting from the available variables in the Variable dropdown.
Only variables that match the data type of the snippet parameter are shown, for example a page parameter, a variable of the page, or an object from a surrounding data container. Variables that come from a data source, a selection, or the return value of an action cannot be passed.
In the example below, the argument for the parameter Amount is the variable Amount:
Expression-Based Arguments
Expression-based arguments allow you to use functions and follow associations within the expression to set the argument value. The expression must return a value that matches the data type of the snippet parameter.
In the example below, the argument for the parameter Amount is the expression $Amount * 2, which multiplies the variable Amount that is available at the snippet call by 2:
Styling
Design Properties Section
Common Section
Performing Specific Actions
To perform actions on a snippet call, select it on a page and right-click it. The list of possible actions opens. While some actions from this list, such as Select snippet, are a quick way to set the properties, the following actions are specific actions that you can perform:
- Show snippet – opens a snippet selected for a snippet call
- Inline snippet – turns the snippet call into widgets that the selected snippet consists of
Inline Snippet
When you select Inline snippet, Studio Pro will analyze the snippet call to determine if it is safe to inline. If it is safe, the following will occur:
- The snippet call will be replaced by the contents of the snippet
- All references to the snippet parameters will be rewritten to refer to the objects, variables, or expressions to which they are mapped in the Snippet settings of the snippet call
- If the snippet has variables, they will be created on the page or snippet that contains the snippet call
This is basically the inverse operation of Extract Snippet.
Not every snippet call can be inlined, because certain configurations cannot be represented correctly outside a snippet. Attempting to inline such a snippet call could result in a consistency error or produce inlined content which does not have the same behavior as the original snippet call. In this case, a warning dialog box is shown to ask whether you want to proceed:
Limitations
The following are examples of configurations which cannot be correctly inlined:
- A Data view with a Context data source using an association of a snippet parameter (if that parameter has been mapped using an expression)
- An attribute widget (such as Text box) using an attribute of a snippet parameter (if that parameter has been mapped using an expression)
In such cases, the inlined content needs to be fixed manually by adding or removing a Data view (depending on the configuration) and reconfiguring the affected widgets to refer to the correct object again.