# os.ReadFile can not find the mounted path

**URL:** <https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897>\
**Category:** support\
**Created:** [October 10, 2024, 10:49pm UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897 "2024-10-10T22:49:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sedyh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sedyh/32/23068_2.png) [@sedyh](https://discourse.gohugo.io/u/sedyh)\
**Post date:** [October 10, 2024, 10:49pm UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897/1 "2024-10-10T22:49:01Z")

</div>

Hello, I’ve mounted static directory in order to get access to some resources in `hugo.toml` like this:

```auto
  [[module.mounts]]
    source = 'static'
    target = 'assets'

```

I can’t get readFile function to work in a snippet:

```auto
{{< code source="static/examples/bas_con_sin.txt" language="go" >}}

```

Which is:

```auto
start
{{ $language := .Get "language" }}
{{ $source := .Get "source" }}
{{ $options := .Get "options" }}

{{ with $source | readFile }}
{{ highlight (trim . "\n") $language $options }}
{{ end }}
end

```

How its look like:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/2/4/245be5d50e130fd4123144d96168cd29910ffddd.png)

Here is my sources:

> **[GitHub - sedyh/eui: A tutorial for Ebiten UI](https://github.com/sedyh/eui)**
>
> A tutorial for Ebiten UI

Have I did something wrong with the config?

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [October 11, 2024, 7:13am UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897/2 "2024-10-11T07:13:19Z")

</div>

the mount has nothing to do with `readFile`. _readFile_ only sees your “real” filesystem not the virtual one.

- `static/examples/bas_con_sin.txt` will work

Code defensive and check the result of `readFile` (same for $language)

```auto
{{ with $source | readFile }}
  {{ highlight (trim . "\n") $language $options }}
{{ else }}
  {{ errorf "could not readFile: %s" $source }}
{{ end }}

```

### Now to your problem:

you wrapped the call to your shortcode within another one.

Use the `{{< expand >}}` syntax instead of {{% %}}

```auto
{{< expand title="Full example" >}}
{{< code source="examples/bas_con_sin.txt" >}}
{{% /expand %}}

```

#### TL;TR

There’s a difference when calling shortcodes using `{{%` or `{{<`

- The inner `{{< code ...` will return plain HTML (the highlighted content)
- The outer `{{% expand ...` will receive that as input and try to render it as Markdown

Since rendering HTML in Markdown is turned off by default in hugo see [unsafe](https://gohugo.io/getting-started/configuration-markup/#rendererunsafe)

The highlighting result is replaced with “” (check it your public folder)

read more about the difference here

> **[Shortcodes](https://gohugo.io/content-management/shortcodes/#use-shortcodes)**
>
> Use embedded, custom, or inline shortcodes to insert elements such as videos, images, and social media embeds into your content.

---

<div class="post-metadata">

**Author:** ![sedyh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sedyh/32/23068_2.png) [@sedyh](https://discourse.gohugo.io/u/sedyh)\
**Post date:** [October 11, 2024, 10:09am UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897/3 "2024-10-11T10:09:11Z")

</div>

Thanks a lot for this.  
I guess I should re-read the documentation next time I want to ask a question.

---

<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:** [October 11, 2024, 10:19am UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897/4 "2024-10-11T10:19:39Z")

</div>

There’s a long story here, but I would strongly recommend that you use Hugo’s Resource abstraction instead of the readFile function, e.g.

- Mount some folder into /assets
- Use resources.Get etc.

---

<div class="post-metadata">

**Author:** ![McShelby](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mcshelby/32/15112_2.png) [@McShelby](https://discourse.gohugo.io/u/McShelby)\
**Post date:** [October 11, 2024, 3:06pm UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897/5 "2024-10-11T15:06:38Z")

</div>

Hi @sedyh.

As you most likely are fiddling around with the Relearn theme, you could just try

````auto
```go
{{% include "examples/bas_con_sin.txt" %}}
```

````

or with expand

````auto
{{% expand title="Full example" %}}
```go
{{% include "examples/bas_con_sin.txt" %}}
```
{{% /expand %}}

````

This will save you from writing your own `code` shortcode.

---

<div class="post-metadata">

**Author:** ![sedyh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sedyh/32/23068_2.png) [@sedyh](https://discourse.gohugo.io/u/sedyh)\
**Post date:** [October 11, 2024, 3:24pm UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897/6 "2024-10-11T15:24:18Z")

</div>

Oh, cool, I didn’t expect that.  
In fact, I need not just a code listing, but an insertion of several snippets by id from the same file.

I think I should make a separate topic for this…

> [@Shortcode for pasting multiple snippets from single file](https://discourse.gohugo.io/t/shortcode-for-pasting-multiple-snippets-from-single-file/51906):
>
> Hello, I want to make a shortcode which allows me to paste multiple snippets from single file by their id. I.e. I want to place that file in static folder: // START full func NewGame() \*Game { // START root root := widget.NewContainer( widget.ContainerOpts.BackgroundImage( image.NewNineSliceColor(colornames.Gainsboro), ), ) // END root return &Game{ ui: &ebitenui.UI{Container: root}, } } // END full And pull different snippets from it, like this: {{\< code source="static/exampl…

---

<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:** [October 13, 2024, 3:24pm UTC](https://discourse.gohugo.io/t/os-readfile-can-not-find-the-mounted-path/51897/7 "2024-10-13T15:24:56Z")

</div>

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