The Full Partial Series Part 2: Returning partials!

This is meta description

Here’s a simple footnote,1 and here’s a longer one.2

  1. Buka terminal Ctrl + U

As we covered in several articles before including this series’ first part, Hugo as a template engine focuses mainly on building template files. As a result, even its most valued partials, while very good at printing stuff, were until this year unable to return typed value.

It all changed with Hugo 0.55.0 when the return statement was introduced to the partial API! Then all of a sudden partials became powerful reusable functions to be consumed by more conventional template files!

In the second part of our Full Partial Series we’ll first cover the fundamentals of this partials’ feature before getting into some pretty detailed code use cases!


Before return

Before return, when partials could only print, a lot of people still relied on them to create reusable pieces of code that served other purposes than simple templating. For example, you could turn a relative image url to its S3 counterpart like so:

# layouts/partial/FormatURL.html
{{- $S3Domain := site.Params.s3Domain -}}
{{- printf "%s/%s" $S3Domain . | safeHTMLAttr -}}

Websites built with Hugo are extremely fast and secure. Hugo sites can be hosted anywhere…and work well with CDNs. Hugo sites run without the need for a database or dependencies on expensive runtimes like Ruby, Python, or PHP. We think of Hugo as the ideal website creation tool with nearly instant build times, able to rebuild whenever a change is made.

— Paraphrased from “What is Hugo”.

Percobaan Tabel

Short Medium Long
Read through the System design topics to get a broad understanding of how systems work 👍 👍 👍
Read through a few articles in the Company engineering blogs for the companies you are interviewing with 👍 👍 👍
Read through a few Real world architectures 👍 👍 👍
Review How to approach a system design interview question 👍 👍 👍
Work through System design interview questions with solutions Some Many Most
Work through Object-oriented design interview questions with solutions Some Many Most
Review Additional system design interview questions Some Many Most

The Hugo configuration file is by default in TOML format. Its standard name is config.toml and located in the project’s root folder. But we can also configure Hugo’s settings in JSON and YAML format. For JSON, we build drafted content with the "buildDrafts": true line. And with a YAML configuration file we use buildDrafts: true.

This is a very good tip.

Demikian tulisan ini semoga bermanfaat.

Referensi :

  1. This is the first footnote. [return]
  2. Here’s one with multiple paragraphs and code.

    Indent paragraphs to include them in the footnote.

    { my code }

    Add as many paragraphs as you like.



Compassionate entrepreneur on a mission to end homelessness. #jshomes Javascript, tech education, electronic music, photography, film, viral apps.

Further reading


comments powered by Disqus