# .Page.File.Dir : Problem with output

**URL:** <https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683>\
**Category:** support\
**Created:** [August 9, 2023, 2:00pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683 "2023-08-09T14:00:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rufus42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rufus42/32/17482_2.png) [@rufus42](https://discourse.gohugo.io/u/rufus42)\
**Post date:** [August 9, 2023, 2:00pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/1 "2023-08-09T14:00:48Z")

</div>

Helle everyone,

I’m using `{{ .Page.File.Dir }}` in my template  
It renders as `./dirA%5dirB%5` instead of `./dirA/dirB/`.

How to change **%5** to **/**?  
What am I doing wrong?

Thank you very much and many greetings  
ruphus 42

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [August 9, 2023, 2:41pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/2 "2023-08-09T14:41:06Z")

</div>

I couldn’t reproduce it, if you’re using it as an element attribute value, `safeHTMLAttr` may help, for example.

```go
<p {{ printf `data-dir="%s"` .Page.File.Dir | safeHTMLAttr }}></p>

```

---

<div class="post-metadata">

**Author:** ![rufus42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rufus42/32/17482_2.png) [@rufus42](https://discourse.gohugo.io/u/rufus42)\
**Post date:** [August 9, 2023, 3:24pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/3 "2023-08-09T15:24:59Z")

</div>

Thank you @razon , it doesn’t help.

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [August 9, 2023, 3:34pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/4 "2023-08-09T15:34:55Z")

</div>

Cloud you please provide a reproducible code.

---

<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:** [August 9, 2023, 3:41pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/5 "2023-08-09T15:41:44Z")

</div>

> [@rufus42](#):
>
> It renders as `./dirA%5dirB%5`

Really?

Are you sure it’s not:

> It renders as `./dirA%5CdirB%5C`

---

<div class="post-metadata">

**Author:** ![rufus42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rufus42/32/17482_2.png) [@rufus42](https://discourse.gohugo.io/u/rufus42)\
**Post date:** [August 9, 2023, 4:06pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/6 "2023-08-09T16:06:55Z")

</div>

Hello @jmooring , thanks for your eye.  
You are right, it renders as `./dirA%5CdirB%5C`.

So the question is: How to change **%5c** to **/**?  
What am I doing wrong?

---

<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:** [August 9, 2023, 4:12pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/7 "2023-08-09T16:12:34Z")

</div>

You’re on a Windows system, so the OS path separators are backslashes (`\`). The hex representation is `5C`.

If you are trying to use `.File.Dir` to build a URL or something, pass it through `path.Clean`.

---

<div class="post-metadata">

**Author:** ![rufus42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rufus42/32/17482_2.png) [@rufus42](https://discourse.gohugo.io/u/rufus42)\
**Post date:** [August 15, 2023, 6:50pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/8 "2023-08-15T18:50:37Z")

</div>

Thank you @jmooring, it doesn’t help.  
Is there another way to get the URL?

---

<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:** [August 15, 2023, 6:51pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/9 "2023-08-15T18:51:18Z")

</div>

Please post a link to the public repository for your project.

See [Requesting Help](https://discourse.gohugo.io/t/requesting-help/9132).

> Let us see your code
> 
> Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
> 
> If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

---

<div class="post-metadata">

**Author:** ![rufus42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rufus42/32/17482_2.png) [@rufus42](https://discourse.gohugo.io/u/rufus42)\
**Post date:** [August 15, 2023, 6:57pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/10 "2023-08-15T18:57:18Z")

</div>

Thank you again for your good will @jmooring.  
I had a typo.  
Your answer solved my problem by using

```auto
{{ path.Clean .Page.File.Dir }}

```

---

<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 17, 2023, 6:57pm UTC](https://discourse.gohugo.io/t/page-file-dir-problem-with-output/45683/11 "2023-08-17T18:57:55Z")

</div>

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