Comment corriger Hugo : can't evaluate field IsServer in type interface {}

Problème :

En construisant votre site Hugo, vous voyez un message d’erreur comme le suivant :

hugo_isserver_error.txt
03:27:57.943	ERROR render of "page" failed: "/opt/buildhome/repo/themes/tailbliss/layouts/_default/baseof.html:5:7": execute of template failed: template: _default/single.html:5:7: executing "_default/single.html" at <partial "head.html" .>: error calling partial: "/opt/buildhome/repo/themes/tailbliss/layouts/partials/head.html:25:6": execute of template failed: template: partials/head.html:25:6: executing "partials/head.html" at <hugo>: can't evaluate field IsServer in type interface {}

Solution

Le problème est causé par Hugo ne trouvant pas .IsServer :

error_excerpt.txt
can't evaluate field IsServer in type interface {}

par exemple dans le code de template suivant :

hugo_template_example.html
{{ if hugo.IsServer }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />
{{ end }}

Cependant, .IsServer a seulement été ajouté à Hugo dans la version 0.120.0, donc si vous utilisez une version plus ancienne, vous verrez cette erreur..

La correction est facile. Vous pouvez soit :

Note : Pour Cloudflare Pages vous pouvez définir la variable d’environnement de déploiement HUGO_VERSION à 0.120.0 ou plus récent pour corriger ce problème. J’ai testé cela avec 0.134.2 et cela fonctionnait correctement.


Consultez les articles similaires par catégorie : Hugo