Error calling partial - experience.html - <.date_end>

Hi there!

Am trying to run my hugo-supported page with the academic theme. Last time I checked up on it, it was running and it was at the end of March 2021. Today I wanted to add some information on it and I had to face the following error message:

Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: 
template: index.html:18:8: executing "main" at <partial "widget_page.html" .>: error calling partial:
 execute of template failed: template: partials/widget_page.html:79:9: executing 
"partials/widget_page.html" at <partial $widget_path $widget_args>: error calling partial:
 "/Users/atantos/Documents/LAL2A/Page/layouts/partials/widgets/experience.html:40:23": execute of
 template failed: template: partials/widgets/experience.html:40:23: executing 
"partials/widgets/experience.html" at <.date_end>: can't evaluate field Format in type *errors.errorString

I have not updated hugo for some time by now and the version I have on my machine is definitely not a version 0,8X. Moreover, the hugo academic template has been updated many times since March and apparently I never followed the breaking changes. However, the page was up and running last March and I tried to run earlier version of Hugo, just in case. I tried running all hugo version back to 0.79 and I kept getting the same error.
Am far from an expert in Hugo and the error is probably due to some naive mistake. However, I did not change anything to the code and there is no way I can figure out what is happening.

Here is the experience.html file:

{{ $ := .root }}
{{ $page := .page }}

<!-- Experience widget -->
<div class="row">
  <div class="col-12 col-lg-4 section-heading">
    <h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
    {{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
  </div>
  <div class="col-12 col-lg-8">
    {{ with $page.Content }}{{ . }}{{ end }}

    {{ if $page.Params.experience }}
    {{ $exp_len := len $page.Params.experience }}
    {{ range $idx, $key := sort $page.Params.experience ".date_start" "desc" }}
    <div class="row experience">
      <!-- Timeline -->
      <div class="col-auto text-center flex-column d-none d-sm-flex">
        <div class="row h-50">
          <div class="col {{if gt $idx 0}}border-right{{end}}">&nbsp;</div>
          <div class="col">&nbsp;</div>
        </div>
        <div class="m-2">
          <span class="badge badge-pill border {{if not .date_end}}exp-fill{{end}}">&nbsp;</span>
        </div>
        <div class="row h-50">
          <div class="col {{if lt $idx (sub $exp_len 1)}}border-right{{end}}">&nbsp;</div>
          <div class="col">&nbsp;</div>
        </div>
      </div>
      <!-- Content -->
      <div class="col py-2">
        <div class="card">
          <div class="card-body">
            <h4 class="card-title exp-title text-muted mt-0 mb-1">{{.title | markdownify | emojify}}</h4>
            <h4 class="card-title exp-company text-muted my-0">
              {{- with .company_url}}<a href="{{.}}" target="_blank" rel="noopener">{{end}}{{.company | markdownify | emojify}}{{with .company_url}}</a>{{end -}}
            </h4>
            <div class="text-muted exp-meta">
              {{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }} –
              {{ if .date_end}}
                {{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }}
              {{else}}
                {{ i18n "present" | default "Present" }}
              {{end}}
              {{with .location}}
                <span class="middot-divider"></span>
                <span>{{.}}</span>
              {{end}}
            </div>
            {{with .description}}<div class="card-text">{{. | markdownify | emojify}}</div>{{end}}
          </div>
        </div>
      </div>
    </div>
    {{end}}
    {{end}}
  </div>
</div>

And here is the widget_page.html:

{{/* Notify JS that this is a widget page */}}
<span class="js-widget-page d-none"></span>

{{/* Get widget page */}}
{{ $page := "" }}
{{ if .IsHome }}
  {{ $page = "/home" }}
{{ else }}
  {{ $page = .File.Path }}
{{ end }}
{{ $headless_bundle := site.GetPage $page }}
{{/* Check homepage exists */}}
{{ if not $headless_bundle }}
  {{ errorf "Homepage not found or duplicate homepages detected for a localization! Add the `home/` folder (especially `/home/index.md`) to each language's content folder. For example, your site should have a `content/home/` folder containing `index.md` and your homepage sections, or for multi-language sites, `content/en/home/` and `content/zh/home/` etc. Refer to the 'Build Your Homepage' and 'Language' documentation at https://sourcethemes.com/academic/docs/ and the example homepage at https://github.com/gcushen/hugo-academic/tree/master/exampleSite/content/home/index.md ." }}
{{ end }}

{{/* Load page sections */}}
{{ range $index, $st := where ( $headless_bundle.Resources.ByType "page" ) ".Params.active" "!=" false }}
  {{/* Begin widget styling */}}
  {{ $bg := $st.Params.design.background }}
  {{ $style := "" }}

  {{ if $bg.color }}
    {{ $style = printf "background-color: %s;" ($bg.color | default "transparent") }}
  {{ end }}

  {{ if and $bg.gradient_start $bg.gradient_end }}
    {{ $style = printf "%sbackground-image: linear-gradient(%s, %s);" $style $bg.gradient_start $bg.gradient_end }}
  {{ end }}

  {{ if $bg.image }}
    {{ $darken := "" }}
    {{ if $bg.image_darken }}
      {{ $darken = printf "linear-gradient(rgba(0, 0, 0, %s), rgba(0, 0, 0, %s))," (string $bg.image_darken) (string $bg.image_darken) }}
    {{ end }}
    {{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
    {{ $style = printf "%sbackground-image: %s url('%s');" $style $darken (printf "img/%s" $bg.image | absURL) }}
    {{ with $bg.image_size }}
      {{/* Allow sizes: actual, cover, and contain. */}}
      {{ $style = printf "%sbackground-size: %s;" $style (replace . "actual" "auto") }}
    {{ end }}
    {{ with $bg.image_position }}
      {{/* Allow valid CSS positions including left, center, and right. */}}
      {{ $style = printf "%sbackground-position: %s;" $style . }}
    {{ end }}
  {{ end }}

  {{ with $st.Params.design.spacing.padding }}
    {{ $style_pad := printf "padding: %s;" (delimit . " ") }}
    {{ $style = print $style $style_pad }}
  {{ end }}

  {{ with $st.Params.advanced.css_style }}
    {{ $style = print $style . }}
  {{ end }}

  {{/* Fix Hugo's ContentBaseName returning wrong file base name when page section is within a bundle. */}}
  {{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }}

  {{ $widget := or $st.Params.widget "blank" }}
  {{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}}
  {{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}}

  {{ $widget_path := printf "widgets/%s.html" $widget }}
  {{ $widget_args := dict "root" $ "page" $st "hash_id" $hash_id }}
  {{ $css_classes := $st.Params.advanced.css_class | default "" }}
  {{ $extra_attributes := "" }}
  {{ $use_container := true }}

  {{/* Special case: Slider widget. */}}
  {{ if in (slice "slider") $widget }}
    {{ $css_classes = print $css_classes " carousel slide" }}
    {{ $extra_attributes = printf "data-ride=\"carousel\" data-interval=\"%s\"" (string $st.Params.interval | default "5000") }}
    {{ $use_container = false }}
  {{ end }}

  <section id="{{$hash_id}}" class="home-section {{printf "wg-%s" (replace $widget "_" "-")}} {{if $bg.text_color_light}}dark{{end}} {{if $bg.image}} bg-image{{if ($bg.image_parallax | default true) }} parallax{{end}}{{end}} {{with $css_classes}}{{.}}{{end}}" {{with $style}}style="{{. | safeCSS}}"{{end}} {{print $extra_attributes | safeHTMLAttr}}>
    {{if $use_container}}<div class="container">{{end}}
      {{ partial $widget_path $widget_args }}
    {{if $use_container}}</div>{{end}}
  </section>
{{ end }}

Any help would be greatly appreciated!

Alex

I suspect the problem is the first line of the following snippet:

{{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }} –
{{ if .date_end}}
  {{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }}
{{else}}
  {{ i18n "present" | default "Present" }}
{{end}}

Since this is supposed to be a date range, I think the first line should be:

{{ (time .date_start).Format ($page.Params.date_format | default "January 2006") }} –

If this doesn’t resolve your problem, please post a link to the public repository for your project. See:
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.

Thanks a lot @jmooring for the response! Unfortunately, the change did not make any difference. Here is the link to the public repo with the page’s content. Any help or hint is truly appreciated!

Alex

Problem 1

You attempted to comment out this line:

{{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }}

By doing this:

<!-- {{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }} – -->

That doesn’t work, because the code is still evaluated. When you don’t want code evaluated, do this:

{{/* {{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }} – */}}

Problem 2

Several of your dates cannot be parsed because of format. For example, 2021-3-1 should be written 2021-03-01.

Make these changes:

diff --git a/content/el/home/news.md b/content/el/home/news.md
index 769cdd5..41f706f 100644
--- a/content/el/home/news.md
+++ b/content/el/home/news.md
@@ -23,8 +23,8 @@ date_format = "Jan 2006"
   company = "Συλλογή δεδομένων από τουρκόφωνους ομιλητές"
   company_url = ""
   location = "Εξ αποστάσεως συνάντηση"
-  date_start = "2020-3-18"
-  date_end = "2020-3-18"
+  date_start = "2020-03-18"
+  date_end = "2020-03-18"
   description = """
   Το ΛΟΚΓ2 μόλις ξεκίνησε την συνεργασία με τους αξιόμαχους εκπαιδευτικούς της ελληνικής ως ξένης γλώσσας στο Σισμανόγλειο Μέγαρο και σε άλλες πόλεις της Τουρκίας. Πολλές ευχαριστίες στην κυρία Αχλάδη και στον κύριο Δανέλλη για τη διοργάνωση, την επιτυχή διεξαγωγή της εξαιρετικής συνάντησης και την έναρξη της συνεργασίας μας!
   """
@@ -34,7 +34,7 @@ date_format = "Jan 2006"
   company = ""
   company_url = ""
   location = "Θεσσαλονίκη"
-  date_start = "2020-3-1"
+  date_start = "2020-03-01"
   date_end = ""
   description = """
   Η ερευνητική μας ομάδα μεγάλωσε. Ο Κοσμάς θα μας βοηθήσει με την ανάλυση δεδομένων και η Νίνα θα συμμετάσχει ενεργά στον σχεδιασμό και υλοποίηση των πειραμάτων.
diff --git a/content/en/home/news.md b/content/en/home/news.md
index b27e550..5d9962a 100644
--- a/content/en/home/news.md
+++ b/content/en/home/news.md
@@ -23,8 +23,8 @@ date_format = "Jan 2006"
   company = "Data collection from turkish-speaking learners of Greek as a second language"
   company_url = ""
   location = "Zoom meeting"
-  date_start = "2021-3-18"
-  date_end = "2021-3-18"
+  date_start = "2021-03-18"
+  date_end = "2021-03-18"
   description = """
   LAL2A has just started its cooperation with Sismanoglio Megaro of the Consulate General of Greece in Istanbul. Many thanks go to Ms Achladi and Mr Danellis, whose excellent spirit of cooperation brought us closer not only to afilliated L2-Greek teachers of Sismanoglio Megaro, but also to teachers all over Turkey contributing oral and written productions of turkish-speaking learners of Greek as a second language. We are looking forward to working with them!
   """
@@ -34,7 +34,7 @@ date_format = "Jan 2006"
   company = ""
   company_url = ""
   location = "Thessaloniki"
-  date_start = "2021-3-1"
+  date_start = "2021-03-01"
   date_end = ""
   description = """
   Our research team grows! Kosmas will help us with the data-analytic part of the project and Nina will participate in designing and implementing the planned experiments.

Dear @jmooring !

Thank you very much for the time and the energy to find these “bugs”! Now, I don’t get any errors, but when I run the server on localhost, I get a page with only the partials running but no real content. To see what I mean, please check the running site on http://lal2a.lit.auth.gr/ and the snapshot of what I see when I run the corrected version that does not spit out errors:

Why is this commented?

1 Like

Oh yes! That was it! Am really grateful! It seems while i was making some experiments I left that out and never documented the change…Now, when uncommenting it, everything shows up as expected!

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