# Franklin.jl: when Julia scripting with HTML, how can I get its insertions to work?

**URL:** <https://discourse.julialang.org/t/franklin-jl-when-julia-scripting-with-html-how-can-i-get-its-insertions-to-work/130682>\
**Category:** General Usage\
**Tags:** question, franklin\
**Created:** [July 13, 2025, 10:43am UTC](https://discourse.julialang.org/t/franklin-jl-when-julia-scripting-with-html-how-can-i-get-its-insertions-to-work/130682 "2025-07-13T10:43:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fusion809](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fusion809/32/6080_2.png) [@fusion809](https://discourse.julialang.org/u/fusion809)\
**Post date:** [July 13, 2025, 10:43am UTC](https://discourse.julialang.org/t/franklin-jl-when-julia-scripting-with-html-how-can-i-get-its-insertions-to-work/130682/1 "2025-07-13T10:43:05Z")

</div>

I have this in my utils.jl file:

```julia
function resolve_inserts(html::String)::String
    insert_pattern = r"\{\{\s*insert\s+([a-zA-Z0-9_./\-]+)\s*\}\}"

    return replace(html, insert_pattern => s -> begin
        filename = match(insert_pattern, s).captures[1]
        filepath = joinpath(@ __DIR__ , "_layout", filename)
        if isfile(filepath)
            included = read(filepath, String)
            resolve_inserts(included) # recursive resolution
        else
            "<!-- Could not find: $filename -->"
        end
    end)
end

function hfun_render_footlist()
    index = locvar("index")
    if @isdefined(index)
        return """"""
    else
      mainfile = joinpath(@ __DIR__ , "_layout", "pages_list.html")
      content = read(mainfile, String)
      expanded = resolve_inserts(content)

      return """
      <button type='button' class='collapsible'>Show content pages list</button>
      <div class='content'><p>
      $expanded
      </p></div>
      """
    end
end

```

This works to an extent as it does insert the right HTML when the `@isdefined` condition is activated. But @isdefined is not working as I had hoped. I wanted this to return an empty string if index is defined and return the contents of pages\_list.html (and files referenced in it) otherwise. But instead it seems to returning an empty string regardless of whether index is defined within a page. How do I get the `@isdefined(index)` condition to work? If you know a way to get it to activate only when the file being rendered is index.md without even needing index defined, that’ll be fine, too!

Furthermore, maths blocks are not rendered in pages\_list.html which is surprising. Even in index.md which has:

```julia
~~~
{{ insert pages_list.html
~~~

```

in it. By maths blocks I mean `\(...maths...\)` like `\(\displaystyle \int_{-\infty}^{\infty} \dfrac{x^2\cos{mx}}{(x^4+a^4)^2} dx\)`. Is there a way to fix this?

---

<div class="post-metadata">

**Author:** ![fusion809](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fusion809/32/6080_2.png) [@fusion809](https://discourse.julialang.org/u/fusion809)\
**Post date:** [July 13, 2025, 11:11am UTC](https://discourse.julialang.org/t/franklin-jl-when-julia-scripting-with-html-how-can-i-get-its-insertions-to-work/130682/2 "2025-07-13T11:11:56Z")

</div>

I have answered my first query, namely how I get `hfun_render_footlist` to return an empty string if the document I have opened is index.md. I found this code:

```julia
function resolve_inserts(html::String)::String
    insert_pattern = r"\{\{\s*insert\s+([a-zA-Z0-9_./\-]+)\s*\}\}"

    return replace(html, insert_pattern => s -> begin
        filename = match(insert_pattern, s).captures[1]
        filepath = joinpath(@ __DIR__ , "_layout", filename)
        if isfile(filepath)
            included = read(filepath, String)
            resolve_inserts(included) # recursive resolution
        else
            "<!-- Could not find: $filename -->"
        end
    end)
end

function hfun_render_footlist()
    rpath = locvar("fd_rpath");
    if (rpath == "index.md")
        return """"""
    else
      mainfile = joinpath(@ __DIR__ , "_layout", "pages_list.html")
      content = read(mainfile, String)
      expanded = resolve_inserts(content)

      return """
      <button type='button' class='collapsible'>Show content pages list</button>
      <div class='content'><p>
      $expanded
      </p></div>
      """
    end
end`

```

does the trick. I still cannot get the maths blocks in index.md rendered. Even though it is rendered in the footnotes (where `hfun_render_footlist()` is run).

---

<div class="post-metadata">

**Author:** ![fusion809](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fusion809/32/6080_2.png) [@fusion809](https://discourse.julialang.org/u/fusion809)\
**Post date:** [July 13, 2025, 11:17am UTC](https://discourse.julialang.org/t/franklin-jl-when-julia-scripting-with-html-how-can-i-get-its-insertions-to-work/130682/3 "2025-07-13T11:17:35Z")

</div>

Never mind. I just needed to set hasmath to true in my index.md file.
