# Include a svg file from static folder to a template

**URL:** https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338
**Category:** support
**Created:** [January 31, 2025, 6:28pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338 "2025-01-31T18:28:42Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![malde11](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@malde11](https://discourse.gohugo.io/u/malde11)
#### Post date: [January 31, 2025, 6:28pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/1 "2025-01-31T18:28:42Z")

</div>

Hi,  
I want to inlcude/import a svg-file from static folder in to a template(navbar), so that the code looks cleaner. It is working, when the svg-code is in the template, but they are so big/large.

At the moment I have got the svg-files in the partial folder and include it from there, but I want to access them from the static folder.

My navbar want to include it here:

```auto
<nav>
  <!-- Logo and Brand -->
  <div class="logo-brand-wrapper">
    <a href="{{ .Site.BaseURL | relLangURL }}">
        {{ partial "logo.html" . }} ---> want inlcude from static
    </a>
    <h1 id="brand-headline">
      <a class="navbar-brand" href="{{ .Site.BaseURL | relLangURL }}">
          <span class="brand-name">Ketten</span>beil
      </a>
    </h1>

  <!-- Burger Menu -->
    <a href="#" id="burgerMenu" class="icon">
      {{ partial "burger-menu.html" . }} ---> want to include from static
    </a>
  </div>

  <!-- Top Navigation Menu -->
  <ul class="topnav" id="myTopnav">
    {{ range site.Menus.main }}
      <li class="nav-item">
        <a class="nav-link" href="{{ .URL }}">
          {{ partial "menu-arrow.html" . }} ---> want to include from static
          {{ .Name }}
        </a>
      </li>
    {{ end }}
  </ul>
</nav>

```

As I said, I do not want them include/import from partial.  
And a second questions, why are the html comments not shown in the inspector/browser?

Thanks

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [January 31, 2025, 6:43pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/2 "2025-01-31T18:43:22Z")

</div>

> [@malde11](#):
>
> why are the html comments not shown

[https://gohugo.io/templates/introduction/#comments](https://gohugo.io/templates/introduction/#comments)

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [January 31, 2025, 6:46pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/3 "2025-01-31T18:46:36Z")

</div>

> [@malde11](#):
>
> so that the code looks cleaner

Are you talking about the template code, or the published HTML?

---

<div class="post-metadata">

### Author: ![malde11](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@malde11](https://discourse.gohugo.io/u/malde11)
#### Post date: [January 31, 2025, 6:51pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/4 "2025-01-31T18:51:06Z")

</div>

about the template code 🙂  
If the svg is in the template code it is hard to read.

want them from the static folder, if it works.

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [January 31, 2025, 6:52pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/5 "2025-01-31T18:52:31Z")

</div>

Sorry, I don’t understand. This looks clean to me:

```plaintext
{{ partial "logo.html" . }} 

```

---

<div class="post-metadata">

### Author: ![malde11](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@malde11](https://discourse.gohugo.io/u/malde11)
#### Post date: [January 31, 2025, 6:55pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/6 "2025-01-31T18:55:33Z")

</div>

this is in the `{{ partial "logo.html" . }}`

```auto
<svg
    class="brand-logo"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:cc="http://creativecommons.org/ns#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:svg="http://www.w3.org/2000/svg"
    xmlns="http://www.w3.org/2000/svg"
    version="1.1"
    id="svg3489"
    viewBox="0 0 299.99999 300.00001"
    height="28px"
    width="28px">
    <g transform="translate(0,-752.36214)" id="layer1">
    <g style="fill:#ffffff" id="g80" transform="matrix(1.25,0,0,-1.25,-125.74979,1526.7507)">
    <g style="fill:#ffffff" clip-path="url(#clipPath84)" id="g82">
    <g style="fill:#ffffff" transform="translate(268.4277,517.2104)" id="g88">
        <path id="path90" style="fill:#ffffff;fill-opacity:0;stroke:#ffffff;stroke-width:12;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m 0,0 c 0,0 29.621,-14.659 37.722,-13.469 5.156,0.757 10.116,-23.64 -5.366,-33.928 -10.319,-6.859 -76.583,21.185 -166.17,83.082 0,0 -2.714,69.646 33.38,58.013 0,0 7.635227,-5.65029 17.879707,-14.278048 C -62.243415,62.314415 -31.676163,33.505141 -30.021,13.822 c 4.526,-53.848 -15.717,-120.649 1.745,-138.572 26.102,-26.794 -194.062,49.479 -45.48,39.361 0,0 64.125,93.404 73.756,85.389 z" />
    </g>
    </g>
    </g>
    </g>
</svg>

```

Dont want them in partial… is there no way to include them from the static folder?

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [January 31, 2025, 6:59pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/7 "2025-01-31T18:59:52Z")

</div>

I would do this:

```plaintext
assets/
└── images/
    └── svg/
        └── foo.svg

```

layouts/partials/svg.html

```plaintext
{{- $path := printf "images/svg/%s.svg" . }}
{{- with resources.Get $path }}
  {{ .Content | safeHTML }}
{{- else }}
  {{- errorf "The 'svg' partial was unable to find %s" $path }}
{{- end }}

```

The call it from a template like this:

```plaintext
{{ partial "svg.html" "foo" }}

```

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [January 31, 2025, 7:04pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/8 "2025-01-31T19:04:25Z")

</div>

Revised: cache it.

```auto
{{ partialCached "svg.html" "foo" }}

```

---

<div class="post-metadata">

### Author: ![malde11](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@malde11](https://discourse.gohugo.io/u/malde11)
#### Post date: [January 31, 2025, 7:42pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/9 "2025-01-31T19:42:27Z")

</div>

Shall I use this:

> [@jmooring](#):
>
> `{{ partialCached "svg.html" "foo" }}`

instead of this:

> [@jmooring](#):
>
> `{{ partial "svg.html" "foo" }}`

? 😃

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [January 31, 2025, 7:43pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/10 "2025-01-31T19:43:33Z")

</div>

Yes, use the first one.

---

<div class="post-metadata">

### Author: ![malde11](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@malde11](https://discourse.gohugo.io/u/malde11)
#### Post date: [January 31, 2025, 7:46pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/11 "2025-01-31T19:46:40Z")

</div>

thanks

---

<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: [February 2, 2025, 7:47pm UTC](https://discourse.gohugo.io/t/include-a-svg-file-from-static-folder-to-a-template/53338/12 "2025-02-02T19:47:14Z")

</div>

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