# Best practice for merging variables into a string template

**URL:** <https://community.make.com/t/best-practice-for-merging-variables-into-a-string-template/52122>\
**Category:** Questions\
**Tags:** mapping\
**Created:** [August 21, 2024, 9:23pm UTC](https://community.make.com/t/best-practice-for-merging-variables-into-a-string-template/52122 "2024-08-21T21:23:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![samliew](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/samliew/32/13327_2.png) [@samliew](https://community.make.com/u/samliew)\
**Post date:** [August 22, 2024, 5:52am UTC](https://community.make.com/t/best-practice-for-merging-variables-into-a-string-template/52122/2 "2024-08-22T05:52:27Z")

</div>

Welcome to the Make community!

Yes, that is possible. I highly recommend using the free [CustomJS integration](https://www.make.com/en/integrations/custom-js) for this to save on operations.

[![Screenshot_2024-08-09_220841](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/e/6/e6fe0903fc5b9e81cfcb958d42db5764ccdf8d08.png)](https://www.make.com/en/integrations/custom-js)

You’ll need a minimum of one “ **Execute Inline JavaScript Code** ” module:

 ![Screenshot_20240822_155126](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/b/c/bc0e54a4adae70666dc3adb24a37e01e89eddcea.png)

## Example Input/Output

 ![Screenshot_20240822_155055](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/2/c/2cd93403bc927c94001d57983a8617246b00aa88.png)

## Module Export - quick import into your scenario

You can **copy** and **paste** this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the **right** of the code, which looks like this:  
 ![](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/c/8/c84e1e230dccfa07b6d6d27e2c0fecf7dc7a5c32.png)

2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

**JSON module export** — paste this directly in your scenario

```json
{"subflows":[{"flow":[{"id":228,"module":"util:SetVariables","version":1,"parameters":{},"mapper":{"variables":[{"name":"template","value":"You are a marketing consultant working for {company-name} and are tasked with {assignment}."},{"name":"replacements","value":"{ \n \"company-name\": \"Your Company Name\",\n \"assignment\": \"Your Assignment\"\n}"}],"scope":"roundtrip"},"metadata":{"designer":{"x":73,"y":-2120}}},{"id":223,"module":"custom-js:inlineexecutev2","version":1,"parameters":{" __IMTCONN__":2457341,"jscode":"return input.string.replace(/{([^{}]*)}/g, (match, key) => input.replacements[key] || match);","returnValueType":"text"},"mapper":{"input":"{\n \"string\": \"{{228.template}}\",\n \"replacements\": {{228.replacements}}\n}"},"metadata":{"designer":{"x":318,"y":-2119,"name":"Replace All"},"parameters":[{"name":" __IMTCONN__","type":"account:custom-js2","label":"Connection","required":true},{"name":"jscode","type":"text","label":"JavaScript Code","required":true},{"name":"returnValueType","type":"select","label":"Return Type","required":true,"validate":{"enum":["text","collection","array","binary"]}}]}}]}],"metadata":{"version":1}}

```

_Note: Did you know you can reduce the size of blueprints and module export code like the above, using the [Make Blueprint Scrubber](https://community.make.com/t/free-tool-reduce-blueprint-module-export-by-removing-extra-details/50697)?_

Hope this helps! Let me know if there are any further questions or issues.

— @samliew

* * *

P.S.: Did you know, [the concepts](https://community.make.com/t/make-academy-course-overview/29699) of about 70% of questions asked on this forum are already covered in the [Make Academy](https://academy.make.com). Investing some effort into it will save you lots of time and frustration using Make later!

---

_[View the full topic](https://community.make.com/t/best-practice-for-merging-variables-into-a-string-template/52122)._
