{"body_class":"rp-body rp-section- rp-full-js","section":"project","thisUrl":"https://regisphilibert.com/tags/hugo/","title":"Regis Philibert | Hugo","translation_url":null}

Blog#Hugo

Hugo Translator

Go Template is the templating language used by Hugo and other Go systems. Now it is not Twig or Blade or Liquid, don’t get fooled by the familiar curlies. It is a far stretch from those well known Templating Language out there…

{{ printf "Hello %s %s. %s" $firstname (slicestr $middlename 0 1) $lastname }}

What is this 😨

{{ if or (eq firstname 'George') (eq firstname 'Daniel') }}

or that ? 😱

The first time you’re gonna stumble on the syntax above may be a bit deconcerting if you come from more conventional languages.

I spent a lot a time trying to figure out how best to use Go Template.

Using comparison with more familiar syntaxes, I wrote this modest article to try and help unveil the misteries of Go Template

Read more ...

Hugo .Scratch explained

Working variables in Hugo can be complicated when coming from classic languages.

What you usually do :

$greetings = "Good Morning";
if($sky == "dark"){
	$greetings = "Good Night";
}
echo $greetings;

That next bit of code would be tempting :

{{ $greetings := "Good Morning" }}
{{ if eq $sky "dark" }}
	{{ $greetings := "Good Night" }}
{{ end }}
{{ $greetings }}

But that won’t happen :(

The only way to override variables or attach any kind of value to a .Page object is to use .Scratch

.Scratch is a life saver but its documentation is a bit light if, like me, you are not comfortable with the Go language.

Here is my take about Hugo’s .Scratch and how it can help you.

Read more ...