# Templating & Global Variables

**URL:** <https://cl.desmos.com/t/templating-global-variables/3352>\
**Category:** Discussion\
**Tags:** validation, correctness\
**Created:** [May 29, 2021, 4:23pm UTC](https://cl.desmos.com/t/templating-global-variables/3352 "2021-05-29T16:23:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Gleeson](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/mike_gleeson/32/650_2.png) [@Mike\_Gleeson](https://cl.desmos.com/u/Mike_Gleeson)\
**Post date:** [May 29, 2021, 4:23pm UTC](https://cl.desmos.com/t/templating-global-variables/3352/1 "2021-05-29T16:23:52Z")

</div>

I was wondering if in the future it would be possible to implement more reusable templating snippets that can be imported as needed on a screen-by-screen basis. A templating system something like importing JSON-esque stuff into, say, a web application or something.

The way things are now, Activity code is not very DRY: I’m constantly repeating the same snippets of code across many components in an Activity.

To illustrate a simple example I might use this sort of thing stays the same in every math input component I have in an Activity:

```auto
correct = this.numericValue=g.script.correct and this.submitted
submitLabel: "Check My Answer"

correct: correct

suffix:
when this.script.correct "✅"
when this.submitted "🤔"
otherwise ""

```

It’s abstracted enough that it really doesn’t matter what the question is about: same code. But I’m having to write that out or copy and paste it in every single time.

Better I think would be to import that entire swath of code into the component from globals container at the beginning of the Activity, like `response = globals.script` and that’s that, overriding specifics where appropriate.

Too much abstraction? Useful? What do you think?

---

<div class="post-metadata">

**Author:** ![Mike\_Gleeson](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/mike_gleeson/32/650_2.png) [@Mike\_Gleeson](https://cl.desmos.com/u/Mike_Gleeson)\
**Post date:** [August 30, 2024, 9:59pm UTC](https://cl.desmos.com/t/templating-global-variables/3352/2 "2024-08-30T21:59:24Z")

</div>

Revisiting this since it’s been a few years. Global variables would be extremely helpful.

Any support out there?
