# Include external code to posts

**URL:** <https://discourse.gohugo.io/t/include-external-code-to-posts/1379>\
**Category:** support\
**Created:** [June 28, 2015, 10:53am UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379 "2015-06-28T10:53:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![turbo28](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@turbo28](https://discourse.gohugo.io/u/turbo28)\
**Post date:** [June 28, 2015, 10:53am UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/1 "2015-06-28T10:53:55Z")

</div>

I want to include a source code saved externally from article file.

- content/post/article.md

```markdown
# this is title

this is source code

{{< highlight go "/code/sample.go" >}}

```

- static/code/sample.go

```auto
func main() {
    fmt.Printf("hello, world!\n")
}

```

this hope to be equivalent of :

- content/post/article.md

```markdown
# this is title

this is source code

{{< highlight go >}}
func main() {
    fmt.Printf("hello, world!\n")
}
{{< /highlight >}}

```

I read [this page](http://gohugo.io/extras/highlighting/), but all ways seem to require “copy and paste” on markdown file.

This feature is available on Octopress : [http://octopress.org/docs/plugins/include-code/](http://octopress.org/docs/plugins/include-code/) (but generate commapnd takes so long time.)

Thank you.

---

<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:** [June 28, 2015, 12:07pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/2 "2015-06-28T12:07:51Z")

</div>

Currently not possible.

But also discussed here:

> <https://github.com/gohugoio/hugo/issues/796>
>
> Idea from this post:
> http://discuss.gohugo.io/t/inline-ditaa-dot-or-plantuml-sources-in-hugo-posts/589/3
> Similar to Highlight. but for any binary that writes to stdout.
> Two arguments:
> Binary
> Args
> 
> the inner content to stdin
> I don't see...

---

<div class="post-metadata">

**Author:** ![turbo28](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@turbo28](https://discourse.gohugo.io/u/turbo28)\
**Post date:** [June 28, 2015, 2:26pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/3 "2015-06-28T14:26:18Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![Weston\_McNamee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/weston_mcnamee/32/540_2.png) [@Weston\_McNamee](https://discourse.gohugo.io/u/Weston_McNamee)\
**Post date:** [July 17, 2015, 7:18am UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/4 "2015-07-17T07:18:26Z")

</div>

I started a conversation about hybrid `.hugo` content files [over here](http://discuss.gohugo.io/t/huge-problems-with-dry-because-content-files-dont-support-any-logic-like-including-small-partials/1328/7?u=weston_mcnamee), if implemented, this could solve this problem.

---

<div class="post-metadata">

**Author:** ![Mike-EEE](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mike-eee/32/6089_2.png) [@Mike-EEE](https://discourse.gohugo.io/u/Mike-EEE)\
**Post date:** [May 31, 2018, 4:57pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/5 "2018-05-31T16:57:30Z")

</div>

Hello… this was not available in 2015, but how about 2018? 🙂 We are using Hugo for a site and are looking to use it in another one. Currently we have an application compile the content for us, but I am thinking it would be incredibly cool and valuable to simply use built-in functionality if it exists. Thank you for any assistance!

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [May 31, 2018, 5:19pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/6 "2018-05-31T17:19:55Z")

</div>

Have a look at [`readFile`](https://gohugo.io/functions/readfile/).

* * *

See also:

> [@readFile equivalent without html escaping?](https://discourse.gohugo.io/t/readfile-equivalent-without-html-escaping/10914):
>
> I have some SVG files that I want to reference rather than duplicate in a partial. readFile would be awesome if it didn’t html escape the contents of file. Any hints?

---

<div class="post-metadata">

**Author:** ![Mike-EEE](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mike-eee/32/6089_2.png) [@Mike-EEE](https://discourse.gohugo.io/u/Mike-EEE)\
**Post date:** [May 31, 2018, 6:22pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/7 "2018-05-31T18:22:45Z")

</div>

Awesome, thank you @kaushalmodi!

---

<div class="post-metadata">

**Author:** ![gaetawoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gaetawoo/32/16789_2.png) [@gaetawoo](https://discourse.gohugo.io/u/gaetawoo)\
**Post date:** [June 3, 2018, 6:28pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/8 "2018-06-03T18:28:07Z")

</div>

Also I just came across this post: [https://it.knightnet.org.uk/kb/hugo/hugo-snippets/](https://it.knightnet.org.uk/kb/hugo/hugo-snippets/)

In the middle there is a shortcode to do exactly what you want.

---

<div class="post-metadata">

**Author:** ![Mike-EEE](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mike-eee/32/6089_2.png) [@Mike-EEE](https://discourse.gohugo.io/u/Mike-EEE)\
**Post date:** [June 4, 2018, 3:00pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/9 "2018-06-04T15:00:39Z")

</div>

Even better! Thank you @gaetawoo!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/totallyinformation/32/5668_2.png) [@TotallyInformation](https://discourse.gohugo.io/u/TotallyInformation)\
**Post date:** [June 4, 2018, 4:07pm UTC](https://discourse.gohugo.io/t/include-external-code-to-posts/1379/10 "2018-06-04T16:07:00Z")

</div>

> [@gaetawoo](#):
>
> Also I just came across this post: [https://it.knightnet.org.uk/kb/hugo/hugo-snippets/](https://it.knightnet.org.uk/kb/hugo/hugo-snippets/)
> 
> In the middle there is a shortcode to do exactly what you want.

Haha, I’d forgotten I’d put that in there! 😊
