# Using other ways to include content in Hugo?

**URL:** https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425
**Category:** support
**Created:** [June 29, 2019, 8:23pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425 "2019-06-29T20:23:38Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Emma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma/32/6684_2.png) [@Emma](https://discourse.gohugo.io/u/Emma)
#### Post date: [June 29, 2019, 8:23pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/1 "2019-06-29T20:23:38Z")

</div>

Hi all,  
I just wanted to know if there was another way to include content into Hugo themes besides partials? I tried to call content outside of the partial folder but that gave me an error. I am just playing around with new theme ideas. Maybe a bit like the include function in PHP?!

Thank you in advance. E

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [June 29, 2019, 9:01pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/2 "2019-06-29T21:01:37Z")

</div>

One option is to use the `readFile` func [https://gohugo.io/templates/files/#use-readfile](https://gohugo.io/templates/files/#use-readfile)

Another option is to put your content in a page bundle [https://gohugo.io/content-management/page-bundles/#readout](https://gohugo.io/content-management/page-bundles/#readout)

---

<div class="post-metadata">

### Author: ![Emma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma/32/6684_2.png) [@Emma](https://discourse.gohugo.io/u/Emma)
#### Post date: [June 29, 2019, 9:31pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/3 "2019-06-29T21:31:57Z")

</div>

Thank you @zwbetz! Readfile looks interesting, are there any disadvantages using that over partials ? I guess if I need to pass variables maybe ?

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [June 29, 2019, 10:47pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/4 "2019-06-29T22:47:52Z")

</div>

It depends on your use case. Give us an example of content you would be including

---

<div class="post-metadata">

### Author: ![Emma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma/32/6684_2.png) [@Emma](https://discourse.gohugo.io/u/Emma)
#### Post date: [June 30, 2019, 5:30pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/5 "2019-06-30T17:30:30Z")

</div>

Hi @zwbetz I tried using readfile today and created a file called foo.html and added it to my root. The HTML file just has a div with a background colour and “foo” as text, but when I visit my localhost I just see “foo” and not the background colour, the tag I used was: {{readFile “foo.html”}}

Does readfile only pass text ?

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [June 30, 2019, 5:43pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/6 "2019-06-30T17:43:39Z")

</div>

How does the actual rendered source look like? Because you may have to call it like:

```
{{readFile "foo.html" | safeHTML}}
```

---

<div class="post-metadata">

### Author: ![Emma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma/32/6684_2.png) [@Emma](https://discourse.gohugo.io/u/Emma)
#### Post date: [June 30, 2019, 5:46pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/7 "2019-06-30T17:46:58Z")

</div>

AHH I see, I will try to add that tomorrow, I just see the div class of foo and the text inside as it’s just passing it as plain text. I will comment back tomorrow. Thank you zwbetz

---

<div class="post-metadata">

### Author: ![jmalin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmalin/32/7031_2.png) [@jmalin](https://discourse.gohugo.io/u/jmalin)
#### Post date: [June 30, 2019, 10:49pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/8 "2019-06-30T22:49:48Z")

</div>

Several ways to do this, depending on your use case:

**Static HTML, created outside of your Hugo site, that you want to link to**  
Make a directory for the file or files, put them there, and then add `staticDir = [*dirname]*` to your config file. Hugo automatically moves the files in _dirname_ to the root of your site. You can link to them from your content using a short code like `html_ref.html`:

`<a href="{{- .Site.BaseURL -}}/{{- safeHTML (.Get 0) -}}">{{- .Inner -}}</a>`

then `{{< html_ref "someFile.html" >}}someText{{< /html_ref >}}`

**Data file containing YAML, JSON, or TOML**

In the `/data` subdirectory of your Hugo site (I think you can change the name in your config file), put the file containing the data you want to use. Refer to the contents of a key using something like this:

`{{ .Site.Data.someFileName.someKey | markdownify }}`

where someFileName is the name of the data file, and some is a YAML variable or TOML variable or JSON property. I can send examples to people who want one.

**asciidoctor**

In case you’re using asciidoctor or you’re just curious, you can use the asciidoctor `::include` in Hugo content. Use something `::include includes/someFileName.adoc[]`. Shameless plug: if you want to write complex content like documentation, asciidoctor is well worth learning.

---

<div class="post-metadata">

### Author: ![Emma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma/32/6684_2.png) [@Emma](https://discourse.gohugo.io/u/Emma)
#### Post date: [July 1, 2019, 6:21pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/9 "2019-07-01T18:21:18Z")

</div>

Wow thanks for the detailed information on will look into that !) Also was not aware about the staticDir would put the files in my root, super helpful

---

<div class="post-metadata">

### Author: ![Emma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma/32/6684_2.png) [@Emma](https://discourse.gohugo.io/u/Emma)
#### Post date: [July 1, 2019, 6:23pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/10 "2019-07-01T18:23:33Z")

</div>

Yes! {{readFile “foo.html” | safeHTML}} works and can now see the HTML, but unfortunately I can’t pass say {{ . Site.Title }} and see my site name when I include it in a readFile ☹

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [July 1, 2019, 6:55pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/11 "2019-07-01T18:55:09Z")

</div>

This is why I asked for an example of your content. There’s likely a way to get what you want, I just can’t help you unless I see it 🙂

---

<div class="post-metadata">

### Author: ![jmalin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmalin/32/7031_2.png) [@jmalin](https://discourse.gohugo.io/u/jmalin)
#### Post date: [July 1, 2019, 9:02pm UTC](https://discourse.gohugo.io/t/using-other-ways-to-include-content-in-hugo/19425/12 "2019-07-01T21:02:51Z")

</div>

Static files and static directories are an important feature of Hugo that I think could be more fully documented. Most of the Hugo documentation is reference: “Here’s how you do (some technical web or blog feature)”. There’s much less documentation along the lines of “What can I do with Hugo? How do I (some task expressed in terms of the user)”. And really not many detailed examples at all. As a technical writer, I can _see_ what’s wrong. As full-time employee, I don’t have the time to fix it.
