Template Variables
gsTemplate variables in SPIN let you parameterize notebooks with dynamic values, making them more flexible and reusable. Users can customize inputs without modifying the underlying code.Overview
Template variables are defined at the notebook level and can be used in any cell parameter using the{{variable_name}}
syntax. When a notebook session starts, template variables are compiled and executed, making their values available for substitution throughout the notebook.
Variable Types
SPIN supports three types of template variables:1. Text Input Variables (input
)
Text input variables provide a simple text field for user input.
name
: Variable identifier used in{{variable_name}}
substitutionkind
: Must be"input"
default
: Default value displayed in the text fielddescription
: Helper text shown to users
2. Static List Variables (static
)
Static list variables provide a dropdown with predefined options.
name
: Variable identifierkind
: Must be"static"
options
: Array of string values for the dropdowndefault
: Default selected optiondescription
: Helper text
3. Dynamic List Variables (code_python
)
Dynamic list variables execute Python code to generate dropdown options at runtime.
name
: Variable identifierkind
: Must be"code_python"
code
: Python code that returns a list of stringsdescription
: Helper text
Using Template Variables
In Cell Parameters
Substitute template variables in cell parameters using double curly braces:In Splunk Queries
In Shell Commands
Advanced Features
Connection Variable Substitution
Template variables can reference runtime files and environment variables in connection configurations:{{runtime_file:<path>}}
: Replaces with contents of a file in the runtime{{runtime_env:<var>}}
: Replaces with environment variable value{{variable_name}}
: Standard template variable substitution
Auto-Application
Template variables are automatically applied when a notebook session connects. The system:- Compiles template variables into executable Python code
- Executes the code in the Jupyter runtime to set variable values
- Makes variables available for substitution in cell parameters
- Replaces
{{variable_name}}
patterns with actual values during cell execution
Best Practices
Naming Conventions
- Use descriptive names:
log_level
instead oflevel
- Use snake_case for consistency
- Avoid spaces and special characters
Default Values
- Always provide sensible defaults for better user experience
- Use common values that work in most scenarios
- For time ranges, use relative values like
-24h
,-1d
Descriptions
- Write clear, concise descriptions
- Explain the purpose and expected format
- Include examples when helpful
Dynamic Variables
- Keep Python code simple and fast
- Handle errors gracefully
- Cache expensive operations when possible
- Return an empty list
[]
if no options are available