# Notes about ioFog application templating
## About current implementation 2.1dev
```yaml
metadata:
name: my-template
spec:
name: my-template
description: My app template
```
* Need to set 2 times the name of the template ?
* Like edge resource it could be usefull to add a version for application template
```yaml
spec:
name: my-template
description: main fiware cloud infrastructure - deployment on one node
version: v0.1.0
```
* Need to inject a new variable set to the `application name`. Could be useful to rebuilt service name with the `application name` suffix.
## Suggestions for a more scripting API
What if we just run `rvaluesVarSubstition` on `applicationTemplateDBObject` (no json parsing).
so loops works any where in template description and any kind of variable type . of course self in this case is going to be undefined.
```javasccript
await rvaluesVarSubstition(applicationTemplateDBObject, { ...defaultVariablesValues, ...userProvidedVariables, self: undefined })
```
This is have a lot of constraints: need to store rawtext but need to know if yaml(coming from iofogctl) or json(direct to iofogCtrl)
Franck: I see that in service createApplicationTemplateEndPoint
```javasccript
applicationJSON: JSON.stringify(applicationTemplateData.application),
```
So this is not JSON form the origin :warning:
An example of use can be: (this example works if you affect baseport and devListRoot )
```yaml
kind: ApplicationTemplateDefinition
apiVersion: iofog.org/v2
metadata: name: "name"
spec:
microservices:
- name: "mySuperDuperMsvc"
agent:
name: {{variable_name}} # Specify the same agent template id allows specifying which microservices needs to run on the same agent
images:
arm: "arm_image"
x86: "x86_image"
container:
rootHostAccess: false
ports:
{%- assign portNo = baseport -%}{% comment %} Set all ports for the microservice 1 {% endcomment %}
{%- assign portnames = "internal,external" | split: "," -%}{%- for portname in portnames %}
- {{ portname }}: {{ portNo }}
{%- assign portNo = portNo | plus: 1 -%}
{% endfor %}
volumes: []
env:
- key: MY_SUPER_SECRET
value: {{my_super_secret}}
- key: devicesList
value: {% assign devList = devListRoot | split: "," -%}{%- for dev in devList %}{{dev}}api/v1/endpoint,{% endfor %}
config:{}
- name: "name2"
agent:
name: {{my_other_agent}}
... ...
container:
ports:
{%- comment %} continue ports allocation for the microservice 2 {% endcomment -%}
{%- assign portnames = "internal,external" | split: "," -%}{%- for portname in portnames %}
- {{ portname }}: {{ portNo }}
{%- assign portNo = portNo | plus: 1 -%}
{% endfor %}
routes: []
variables:
- key: variable_name
description: Agent name for microservice mySuperDuperMsvc
- key: my_super_secret
description: Secret API Key for microservice mySuperDuperMsvc
defaultValue: public_key
- key: baseport
description: port
defaultValue: 8080
- key: devListRoot
description: dev list url
defaultValue: "http://dev1:111/,http://dev2:888/e"
```
### Caveats
* How can we know the variables (key, default etc...) without parsing: split template part from variable def part (new kind VariableTemplateDefinition)