Substr Calculates Length of String to 0 in baseof.html

I found a solution.
@pamubay was right. I realised that I tried to access the File handle outside my block definitions and that doesn’t work.

My workaround is as follows:

  1. in the baseof.html file I define blocks for all the parts I want to replace later, e.g. the favicon and the title.

    {{ block “favicon” . }}
    {{ partial “site-favicon.html” . }}
    {{ end }}

  2. in the layout template I overwrite that blocks and inside the block I have access to the filename:

    {{ define “favicon” }}
    {{ partial “page-favicon.html” . }}
    {{ end }}

With page-favicon.html:

{{ $company := substr $.File.BaseFileName 0 -3 }}
{{ $staticData := (index .Site.Data.v $company) }}
{{ if $staticData }}
<link rel="shortcut icon" href="/{{ $staticData.favicon }}" type="image/x-icon" />
{{ end }}