Skip to main content
Version: v4.4.0

Advanced Inputs

Advanced inputs allow you to apply more complex rules to inputs, this helps you create Templates and Plugins.

Computed Inputs

Through computed-inputs, you can:

  • Create inputs based on other inputs;
  • Use the value in a Template/Plugin that is currently being applied.

See the example using a title filter, the first letter of each name is transformed into an upper case letter:

inputs:
- label: Type your name
name: name
type: text

computed-inputs:
name_formatted: "{{ name | title }}"

Global Input

When you define global inputs in an app (via Template or Plugin), any Plugin can access or modify them.

You must declare a global input via the global: true flag, see the example below:

inputs:
- label: Commit message
type: text
default: example
name: message
required: true
global: true

Example 1: Base Template with global input

In this example, the base Template has a global input you can use in other Plugin applications, this means in the same app where it was created with this Template:

name: global-template
description: Template that has a global input
types:
- app-template
inputs:
- label: Project name
type: text
name: project_name
default: project-name
global: true

As the project_name input was defined as global, any value informed can be used in other Plugins.

Example 2: Plugin using the global input of your Templates

The value of a global input defined in a Template can be used in a Plugin. It is not necessary to define it again in the plugin.yaml file.
To access the input's value defined in a Template, in the Plugin, add the name of the input between double curly braces "{{ ... }}" forming the expression {{ <do-name -input> }}. See the example below using an input "project_name" from a Template, the expression will be {{ project_name }}.

name: global-plugin
description: Plugin that has a input from global input
types:
- app
inputs:
- label: Insert any text
type: text
name: json_body
hooks:
- type: edit-json
trigger: after-render
path: package.json
indent: "\t"
encoding: utf-8
changes:
- jsonpath: "$.name[?name = '{{ project_name }}']"
update:
value: |
{
"name": "other-project",
"version": "1.2.5",
"bin": {
"other-project": "./path/to/project"
}
}

The project_name input value defined in the Template will be used as part of the jsonpath expression used in a Declarative Hook edit-json when applying the Plugin.

Example 3: Plugin using global input as default value in one of its inputs

You can use the global input value to set the default value of a Plugin that will be applied after another Template (or Plugin) has defined a global input:

name: global-plugin
description: Plugin that uses a global input as default value
display-name: globa-plugin
picture: plugin.png
category: backend # Ref: https://docs.stackspot.com/latestcreate-stacks/yaml/#category
compatibility:
- java
- spring
about: docs/about.md
usage: docs/usage.md
use-case: docs/use-case.md
implementation: docs/implementation.md
technologies: # Ref: https://docs.stackspot.com/latestcreate-stacks/yaml/#technologies
- "Api"
types:
- app
inputs:
- label: Project Name
type: text
name: project_name
default: project_name
global: true

Global Computed Inputs

caution

global-computed-inputs accepts Jinja expressions.

See more details on using Jinja on StackSpot

global computed inputs makes it possible to use computed-inputs globally in Templates and Plugins.

Through global-computed-inputs, you can:

  • Use computed-inputs globally;
  • Reuse the input value in subsequent Plugins.

Example 1. Defining a global-computed-input in a base Template

name: global-computed-input-template
description: Template that has a global computed input
types:
- app-template
inputs:
- label: Project name
type: text
name: project_name
default: project-name
global-computed-inputs:
project_name_sanitized: "{{project_name|replace('-', '_')|lower}}"

The project_name_sanitized value can now be used in all subsequent Plugin applications.

Example 2. Plugin using global-computed-input value

Plugin with global-computed-inputs Plugins applied next will have access to the global-computed-inputs value.

To use the project_name_sanitized value defined as global computed input in the previous Template, just set it to {{project_name_sanitized}} in the parse file.

For example, to use this value in a README.md file that would be created by the Plugin:

|_plugin.yaml
|_templates
|_README.MD

README.md

The project_name_sanitized value is {{project_name_sanitized}}.

info

It is not necessary to redefine this part in plugin.yaml.

Was this page helpful?