# Why \`replace\` works for hugo's config file and not 'dict'?

**URL:** <https://discourse.gohugo.io/t/why-replace-works-for-hugos-config-file-and-not-dict/46627>\
**Category:** support\
**Created:** [October 11, 2023, 2:08pm UTC](https://discourse.gohugo.io/t/why-replace-works-for-hugos-config-file-and-not-dict/46627 "2023-10-11T14:08:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/arif/32/20931_2.png) [@Arif](https://discourse.gohugo.io/u/Arif)\
**Post date:** [October 11, 2023, 2:08pm UTC](https://discourse.gohugo.io/t/why-replace-works-for-hugos-config-file-and-not-dict/46627/1 "2023-10-11T14:08:28Z")

</div>

After recently discovering how to use [custom variables in i18n](https://discourse.gohugo.io/t/using-custom-variables-in-translated-files/46496), I was wondering why the same does not work in the config file, but [replace](https://gohugo.io/functions/strings/replace/) does, albeit for variables with single curly brackets like `{year}`.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [October 11, 2023, 5:20pm UTC](https://discourse.gohugo.io/t/why-replace-works-for-hugos-config-file-and-not-dict/46627/2 "2023-10-11T17:20:08Z")

</div>

> [@Arif](#):
>
> I was wondering why the same does not work in the config file, but [replace](https://gohugo.io/functions/strings/replace/) does, albeit for variables with single action `{year}`.

Im not sure I follow the last part, but for the first, I assume you mean that it’s not possible to use Go template syntax in config files. e.g `hugo.toml`, e.g:

```toml
baseURL = "{{ site.BaseURL }}"

```

The short answer, the above is not a TOML thing, and we haven’t implemented “string template expansion” as a generat thing in Hugo. I have deliberately made the above example a little stupid (there’s a chicken and egg situation).

But we have considered adding

- Env var expansion support (e.g. `baseURL = “${MYBASEURL}”, but we kind of have that in place already in a roundabout way.
- Support for Cue ([GitHub - cue-lang/cue: The home of the CUE language! Validate and define text-based and dynamic configuration](https://github.com/cue-lang/cue)) as a config/data format, which should give you more powerful scripting capabilities inside these files.

`

---

<div class="post-metadata">

**Author:** ![Arif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/arif/32/20931_2.png) [@Arif](https://discourse.gohugo.io/u/Arif)\
**Post date:** [October 11, 2023, 8:19pm UTC](https://discourse.gohugo.io/t/why-replace-works-for-hugos-config-file-and-not-dict/46627/3 "2023-10-11T20:19:59Z")

</div>

Understood. My usage example is something like `copyright = "2015-{year}` that I saw somewhere in this forum in the past. Then `replace` works here replacing `{year}` with `now.Format "2006"`. But doing something like `{{ .Year }}` and using `dict` instead returns an error instead (something about `site.Copyright` having 1 argument while it expects 0).

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [October 12, 2023, 7:16am UTC](https://discourse.gohugo.io/t/why-replace-works-for-hugos-config-file-and-not-dict/46627/4 "2023-10-12T07:16:41Z")

</div>

> [@Arif](#):
>
> My usage example is something like `copyright = "2015-{year}` that I saw

OK, what you talk about have some use cases, but in most situations I suspect you will be better off by having the presentation logic in the templates.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [October 14, 2023, 7:17am UTC](https://discourse.gohugo.io/t/why-replace-works-for-hugos-config-file-and-not-dict/46627/5 "2023-10-14T07:17:36Z")

</div>

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