# Passing a "local variable" from template to another "ExecuteAsTemplate"

**URL:** <https://discourse.gohugo.io/t/passing-a-local-variable-from-template-to-another-executeastemplate/54598>\
**Category:** support\
**Created:** [May 1, 2025, 10:49pm UTC](https://discourse.gohugo.io/t/passing-a-local-variable-from-template-to-another-executeastemplate/54598 "2025-05-01T22:49:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 1, 2025, 11:04pm UTC](https://discourse.gohugo.io/t/passing-a-local-variable-from-template-to-another-executeastemplate/54598/2 "2025-05-01T23:04:11Z")

</div>

The context can be your individual context (add a dict, add the page object, whatever). By adding the dot you are adding either the current page or whatever loop you are in (the context changes with `with` and `range`).

You can always use `page` itself to add the context of the current page (on list pages it’s the list page, not the page you might be ranging through). Or create your own dictionary:

```auto
{{ $context := dict "bla" "falsel" }}
{{- $exec := resources.ExecuteAsTemplate "foo.js" $context $script -}}

```

would result in foo.js having `.bla` set to “fasel”.  
If you want to add the page context additionally:

```auto
{{ $context := dict "bla" "falsel" "page" . }}

```

Then `.page` would contain the page context, for instance `.page.Title`, etc.

Is that what you need?

---

_[View the full topic](https://discourse.gohugo.io/t/passing-a-local-variable-from-template-to-another-executeastemplate/54598)._
