# Include content of a URL

**URL:** https://discourse.gohugo.io/t/include-content-of-a-url/27357
**Category:** support
**Created:** [August 4, 2020, 4:34pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357 "2020-08-04T16:34:00Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Ruth\_Motza](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ruth_motza/32/12057_2.png) [@Ruth\_Motza](https://discourse.gohugo.io/u/Ruth_Motza)
#### Post date: [August 4, 2020, 4:34pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/1 "2020-08-04T16:34:00Z")

</div>

Hi,

I am quite new to hugo.

I would like to load content of a markdown file that is available on the internet.  
I found out [here](https://github.com/gohugoio/hugo/issues/247#issuecomment-510148900) I have to write my own shortcode. I tried it the way they mentioned. But when I use it with a URL it always says

```auto
execute of template failed: template: shortcodes/content.html:2:11: executing "shortcodes/content.html" at <readFile>: error calling readFile: file "<myUrl>" does not exist. 

```

But I am sure it is free to access on the internet.

What can I do?

---

<div class="post-metadata">

### Author: ![divinerites](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/divinerites/32/12625_2.png) [@divinerites](https://discourse.gohugo.io/u/divinerites)
#### Post date: [August 4, 2020, 4:56pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/2 "2020-08-04T16:56:01Z")

</div>

> [@Ruth\_Motza](#):
>
> file `<myUrl>` does not exist

Mmmmm … I suspect that somewhere you didn’t replace `<myUrl>` with your **real** url …

---

<div class="post-metadata">

### Author: ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)
#### Post date: [August 4, 2020, 7:07pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/3 "2020-08-04T19:07:28Z")

</div>

> [@Ruth\_Motza](#):
>
> I would like to load content of a markdown file that is available on the internet.

> [@Ruth\_Motza](#):
>
> But I am sure it is free to access on the internet.

To receive assistance you’ll need to share your shortcode. I don’t know of a method used to get the contents of a remote markdown file and render it via shortcode at build time. There’s normally a step involving getting the remote file and moving it to the local filesystem, where functions like `readFile` work.

See [Local file templates | Hugo](https://gohugo.io/templates/files/) for more details. The “remote” calls work for JSON and CSV, where Hugo will retrieve and cache the files for processing, described at [Data templates | Hugo](https://gohugo.io/templates/data-templates/#data-driven-content).

---

<div class="post-metadata">

### Author: ![Ruth\_Motza](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ruth_motza/32/12057_2.png) [@Ruth\_Motza](https://discourse.gohugo.io/u/Ruth_Motza)
#### Post date: [August 5, 2020, 5:51am UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/4 "2020-08-05T05:51:17Z")

</div>

sorry, I guess I wasn’t clear enough, I did not add the URL there as I thought this was overfilling the error message, it does show my actual URL at that placeholder

---

<div class="post-metadata">

### Author: ![Ruth\_Motza](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ruth_motza/32/12057_2.png) [@Ruth\_Motza](https://discourse.gohugo.io/u/Ruth_Motza)
#### Post date: [August 5, 2020, 5:52am UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/5 "2020-08-05T05:52:36Z")

</div>

Hi,

My shortcode is this:

```auto
{{$file := .Get 0}}
{{ $file | readFile | markdownify }}

```

I then use it like this:

```auto
{{% content "https://raw.githubusercontent.com/europace/kex-vorgang-export-api/master/README.md" %}}

```

but I get the error:

```auto
failed to render shortcode "content": failed to process shortcode: "...../layouts/shortcodes/content.html:2:11": execute of template failed: template: shortcodes/content.html:2:11: executing "shortcodes/content.html" at <readFile>: error calling readFile: file "https:/raw.githubusercontent.com/europace/kex-vorgang-export-api/master/README.md" does not exist

```

I did assume that readFile does not take a URL with it, but I could not find another way to make this work and I assumed that somehow this must be possible… ☹

@maiki do you have a suggestion for the shortcode that would allow this? If I do `getJSON` I am not sure what will happen, as this file is not json but markdown… 🤔

---

<div class="post-metadata">

### Author: ![Ruth\_Motza](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ruth_motza/32/12057_2.png) [@Ruth\_Motza](https://discourse.gohugo.io/u/Ruth_Motza)
#### Post date: [August 5, 2020, 6:33am UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/6 "2020-08-05T06:33:03Z")

</div>

so when I do the following in my shortcode:

```auto
{{ getJSON "https://raw.githubusercontent.com/europace/kex-vorgang-export-api/master/README.md" | markdownify}}

```

I get the error:

```auto
Building sites … ERROR 2020/08/05 08:31:18 Failed to get JSON resource "https://raw.githubusercontent.com/europace/kex-vorgang-export-api/master/README.md": invalid character '#' looking for beginning of value

```

So this seems just to work for actual json ☹

---

<div class="post-metadata">

### Author: ![Ruth\_Motza](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ruth_motza/32/12057_2.png) [@Ruth\_Motza](https://discourse.gohugo.io/u/Ruth_Motza)
#### Post date: [August 5, 2020, 1:13pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/7 "2020-08-05T13:13:42Z")

</div>

I have a quickfix for my problem now. It feels very hacky, but I did not find another way.

I now have a shortcode looking like this:

```auto
{{ $repo := .Get 0 }}
{{ $json := getJSON "https://api.github.com/repos/europace/" $repo "/readme" }}
{{ $json.content | base64Decode | markdownify }}

```

Then I call that in my md-file like this:

```auto
{{% europace-content "kex-vorgang-import-api" %}}

```

I am not happy with how it looks, but I am happy that I found something. I will keep this open for a few days as maybe somene has a better solution. Then I will close it 🙂

---

<div class="post-metadata">

### Author: ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)
#### Post date: [August 5, 2020, 1:54pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/8 "2020-08-05T13:54:25Z")

</div>

As you’re discovered, we don’t have a generic “get file via HTTP” template function. `readFile` is for the local OS. Our only “remote get” functions as of today are `getJSON` and `getCSV`.

---

<div class="post-metadata">

### Author: ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)
#### Post date: [August 5, 2020, 7:04pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/9 "2020-08-05T19:04:29Z")

</div>

> [@Ruth\_Motza](#):
>
> It feels very hacky, but I did not find another way.

Your feelings are valid, of course. I wanted to point out:

- markdown is for humans to write readable text that can be rendered in different ways and be easy to remember
- JSON is a data format made for the web

Getting the contents of a remote markdown file via JSON call, I wouldn’t call that hacky, I’d call it, “used as intended”. 🙂

---

<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: [August 7, 2020, 7:04pm UTC](https://discourse.gohugo.io/t/include-content-of-a-url/27357/10 "2020-08-07T19:04:33Z")

</div>

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