# How to interpolate variables in Markdown file?

**URL:** <https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750>\
**Category:** General Usage\
**Tags:** markdown\
**Created:** [December 13, 2017, 11:30pm UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750 "2017-12-13T23:30:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [December 13, 2017, 11:30pm UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/1 "2017-12-13T23:30:50Z")

</div>

Say I have a file `test.md` which contains:

```julia
Hello $user_name

```

Then in the REPL I do:

```julia
julia> user_name = "John"
julia> Markdown.parse_file("test.md") |> Markdown.html

```

This will render `Hello user_name` instead of `Hello John`. How can I get it to eval the interpolated variables?

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [December 14, 2017, 8:12am UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/2 "2017-12-14T08:12:41Z")

</div>

Not possible / easily doable / efficient? Or just insufficiently documented?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [December 14, 2017, 8:53am UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/3 "2017-12-14T08:53:12Z")

</div>

Is [Mustache.jl](https://github.com/jverzani/Mustache.jl) what you’re looking for?

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [December 14, 2017, 9:03am UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/4 "2017-12-14T09:03:32Z")

</div>

Thanks. No Mustaches - I was specifically looking to use Markdown files.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 14, 2017, 9:06am UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/5 "2017-12-14T09:06:40Z")

</div>

Do you want to be able to use arbitrary Julia code or just simple variable substitution?

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [December 14, 2017, 9:12am UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/6 "2017-12-14T09:12:41Z")

</div>

I would like to allow Markdown layouts and views in Genie, _à la_ Jekyll. Functionality similar to string interpolation – so both `$var` and more complex `$(...)` – should be enough. Including large pieces of code into views is a bad practice anyway, so such code should go into a helper function that can be invoked via a construct like `$(Helper.f(...))`.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 14, 2017, 9:29am UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/7 "2017-12-14T09:29:44Z")

</div>

That still means you need to support arbitrary Julia code.

Anyway you can do something like:

```julia
Markdown.parse(include_string(string('"', readstring("test.md"), '"'))) |> Markdown.html

```

Note that this will evaluate the file so you can be pwned if someone put bad stuff in there.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [December 14, 2017, 1:11pm UTC](https://discourse.julialang.org/t/how-to-interpolate-variables-in-markdown-file/7750/8 "2017-12-14T13:11:49Z")

</div>

@kristoffer.carlsson Nice, it works, thanks! That’s OK, these files are meant to be written by the developers.
