# Accessing custom properties within subflow in the template module

**URL:** <https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408>\
**Category:** General\
**Created:** [28 November 2022 22:39 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408 "2022-11-28T22:39:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cryogenicminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cryogenicminer/32/71546_2.png) [@cryogenicminer](https://discourse.nodered.org/u/cryogenicminer)\
**Post date:** [28 November 2022 22:39 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/1 "2022-11-28T22:39:11Z")

</div>

Scenario:

I make a subflow and add a custom string property labeled "text".

Inside a function, I can use env.get("prefixText") to find the property value. What I want is to use it within a template function something like this:

{{flow.text}} This is after the text.

There is some stuff that seems unclear to me in the documentation for the mustache temple node.  
Thank you!

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 November 2022 22:45 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/2 "2022-11-28T22:45:20Z")

</div>

Hi @cryogenicminer - welcome to the forum!

The subflow properties are exposed as environment variables. You should be able to use `{{env.text}}` to access the value.

---

<div class="post-metadata">

**Author:** ![cryogenicminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cryogenicminer/32/71546_2.png) [@cryogenicminer](https://discourse.nodered.org/u/cryogenicminer)\
**Post date:** [28 November 2022 23:22 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/3 "2022-11-28T23:22:22Z")

</div>

Thanks knollary! I tried to put that in directly, and I must not understand exactly still. Here is my test setup:

=\> timestamp ---\> Subflow 1 ---\> msg.payload

Inside the subflow is:

input --\> template ---\> output 1

The subflow properties look like this:

 ![Screen Shot 2022-11-28 at 17.06.01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75fca5e0fb74b2a0608af9b2957ca4e440a25ae8.png)  
And the template is setup to pull that "text" property which should read something like: "TIME 1669676644053"  
 ![Screen Shot 2022-11-28 at 17.06.20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b00d71a0649fd46347972d0a2f981621fb42faf.png)  
But, I can not for the life of me figure out how to get it to show the contents of the property. Thank you for looking at it 🙂 What am I missing?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 November 2022 09:22 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/4 "2022-11-29T09:22:31Z")

</div>

Select the node where you use the subflow, Export it to the clipboard using CTRL+E (or via the menus) and paste it here, using the `</>` button in the forum entry window when you paste it in. Then we will be able to better see what you are doing.

---

<div class="post-metadata">

**Author:** ![cryogenicminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cryogenicminer/32/71546_2.png) [@cryogenicminer](https://discourse.nodered.org/u/cryogenicminer)\
**Post date:** [29 November 2022 14:10 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/5 "2022-11-29T14:10:45Z")

</div>

Ah, my bad. That was in the formatting section of the forum guidelines.

```auto
[
    {
        "id": "7c820e03dbb518ae",
        "type": "subflow",
        "name": "Subflow 1",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 40,
                "y": 40,
                "wires": [
                    {
                        "id": "41763aa8f5bade9b"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 280,
                "y": 40,
                "wires": [
                    {
                        "id": "41763aa8f5bade9b",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [
            {
                "name": "text",
                "type": "env",
                "value": "Time is"
            }
        ],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "41763aa8f5bade9b",
        "type": "template",
        "z": "7c820e03dbb518ae",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{{env.text}} {{payload}}",
        "output": "str",
        "x": 160,
        "y": 40,
        "wires": [
            []
        ]
    },
    {
        "id": "e672d6322ed2b137",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "aae8d4d14b1494c8",
        "type": "inject",
        "z": "e672d6322ed2b137",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 160,
        "y": 40,
        "wires": [
            [
                "e811c22e2fb928d5"
            ]
        ]
    },
    {
        "id": "e811c22e2fb928d5",
        "type": "subflow:7c820e03dbb518ae",
        "z": "e672d6322ed2b137",
        "name": "",
        "env": [
            {
                "name": "text",
                "value": "TIME",
                "type": "str"
            }
        ],
        "x": 320,
        "y": 40,
        "wires": [
            [
                "5521b6e122c9cedf"
            ]
        ]
    },
    {
        "id": "5521b6e122c9cedf",
        "type": "debug",
        "z": "e672d6322ed2b137",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 490,
        "y": 40,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 November 2022 14:25 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/6 "2022-11-29T14:25:27Z")

</div>

That works for me

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/681068908f4e6e965e89fbc7bbdff8af451f28a3.png)

What do you see when you run it?

What versions of node-red (see the bottom of the dropdown menu) and nodejs (run command `node -v`, assuming you are not using Docker) to find out.

---

<div class="post-metadata">

**Author:** ![cryogenicminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cryogenicminer/32/71546_2.png) [@cryogenicminer](https://discourse.nodered.org/u/cryogenicminer)\
**Post date:** [29 November 2022 20:03 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/7 "2022-11-29T20:03:16Z")

</div>

Huh... I just copied what I published here on the forum and re-imported it. Ran it and does not pull the env value example: ` 1669751683715`

Node-red: 2.0.5  
Node: v14.20.1

Oh, and yes, I am not using docker.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 November 2022 20:18 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/8 "2022-11-29T20:18:00Z")

</div>

Can you upgrade to node red 3?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [29 November 2022 20:26 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/9 "2022-11-29T20:26:18Z")

</div>

Support for `env` in the template node was added in Node-RED 3.0

If you aren't able to upgrade, an alternative is to use a Change node before the Template node to set a message property to the env var value, and then reference that message property in the Template.

---

<div class="post-metadata">

**Author:** ![cryogenicminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cryogenicminer/32/71546_2.png) [@cryogenicminer](https://discourse.nodered.org/u/cryogenicminer)\
**Post date:** [29 November 2022 21:06 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/10 "2022-11-29T21:06:50Z")

</div>

Ohhh! ok. It's in a prod environment so I will upgrade, but it will be a while. In the meantime, I will make a cascade of Change nodes or use a Function node to do that. Thanks, you guys are the best!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 December 2022 21:07 UTC](https://discourse.nodered.org/t/accessing-custom-properties-within-subflow-in-the-template-module/71408/11 "2022-12-13T21:07:18Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
