# .File.ContentBaseName: can't evaluate field File in type \*source.File

**URL:** <https://discourse.gohugo.io/t/file-contentbasename-cant-evaluate-field-file-in-type-source-file/49541>\
**Category:** support\
**Created:** [April 29, 2024, 1:55pm UTC](https://discourse.gohugo.io/t/file-contentbasename-cant-evaluate-field-file-in-type-source-file/49541 "2024-04-29T13:55:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cf-sewe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cf-sewe/32/21943_2.png) [@cf-sewe](https://discourse.gohugo.io/u/cf-sewe)\
**Post date:** [April 29, 2024, 1:55pm UTC](https://discourse.gohugo.io/t/file-contentbasename-cant-evaluate-field-file-in-type-source-file/49541/1 "2024-04-29T13:55:31Z")

</div>

After updating Hugo from 0.95 to 0.125 I get an error and I am clueless about the reason.

How can I address this issue?

```plaintext
Start building sites … 
hugo v0.125.3-474c4c02212cf97712c6fbf4159c68822ea6e078+extended linux/amd64 BuildDate=2024-04-22T17:18:35Z VendorInfo=gohugoio

INFO static: removing all files from destination that don't exist in static dirs
INFO static: syncing static files to / duration 15.252404ms
INFO build: step process substep collect files 1414 files_total 1414 duration 69.357788ms
INFO build: step process duration 69.408412ms
INFO build: step assemble duration 27.512643ms
INFO build: step render pages 758 content 755 duration 8.021755044s
INFO build: step postProcess duration 11.802µs
INFO build: duration 8.118929724s
Total in 8145 ms
Error: error building site: render: failed to render pages: render of "section" failed: "/home/runner/work/cplace-doc-ops/cplace-doc-ops/themes/cplace/layouts/space/list.html:93:94": execute of template failed: template: space/list.html:93:94: executing "main" at <.File.ContentBaseName>: can't evaluate field File in type *source.File

[13:44:55] 
[13:44:55] 'hugo' errored after 8.21 s
[13:44:55] Error: Command failed: HUGO_ENV=production; hugo --cleanDestinationDir --printPathWarnings -v 

```

This is the relevant part of list.html:

```html
                    {{- $sub_sections_pages := (union .Pages .Sections) -}}
                    {{ if gt (len $sub_sections_pages) 0 -}}
                        <div class="chapter-list">
                            <ol class="list-unstyled mb-0">
                                {{- range $sub_sections_pages.ByWeight }}
                                    <li>
                                        <a href="{{- .RelPermalink -}}">
                                            {{- if .Title -}}
                                                {{- .Title -}}
                                            {{- else -}}
                                                {{ with .File }}{{- humanize .ContentBaseName -}}{{ end }}
                                            {{- end -}}
                                        </a>

```

---

<div class="post-metadata">

**Author:** ![cf-sewe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cf-sewe/32/21943_2.png) [@cf-sewe](https://discourse.gohugo.io/u/cf-sewe)\
**Post date:** [April 29, 2024, 2:07pm UTC](https://discourse.gohugo.io/t/file-contentbasename-cant-evaluate-field-file-in-type-source-file/49541/2 "2024-04-29T14:07:13Z")

</div>

I found that I had some locations with `{{ with .File }}{{- humanize .File.ContentBaseName -}}{{ end }}`.  
I fixed this by removing the `.File` prefix at such places.

The old Hugo version was more tolerant to this syntax problem it seems. Case closed =)

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [April 29, 2024, 3:07pm UTC](https://discourse.gohugo.io/t/file-contentbasename-cant-evaluate-field-file-in-type-source-file/49541/3 "2024-04-29T15:07:32Z")

</div>

This is a common issue. If you are using `with` then whatever that `with` is checking will be the `.` (dot) inside of the loop.

So this:

```gotemplate
{{ with .File }}
{{- humanize .File.ContentBaseName -}}
{{ end }}

```

is wrong, because inside of the loop the `.` is the `File`. Proper code would be:

```gotemplate
{{ with .File }}
{{- humanize .ContentBaseName -}}
{{ end }}

```

Because inside of the loop the `.` is actually `.File`. I hope that clears it up somehow.

---

<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:** [May 1, 2024, 3:08pm UTC](https://discourse.gohugo.io/t/file-contentbasename-cant-evaluate-field-file-in-type-source-file/49541/4 "2024-05-01T15:08:17Z")

</div>

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