


























Hugo v0.154.0 is the 14th release this year (not counting patch releases) and introduces partial decorators, or “partials with a twist.” This is a very powerful construct that I, @bep, have always wanted to have in Hugo, but I could never wrap my head around an implementation. Until now.
A small and not very useful example:
{{ with partial "b.html" "World" }}Hello {{ . }}{{ end }} {{ define "_partials/b.html" }}<b>{{ inner . }}</b>{{ end }}
The above renders to:
inner keyword can be used zero or more times in a partial template, typically with different data (e.g. pages in a range), and its presence signals a reversal of the execution -- the callee becomes the caller.This release also brings some new utility funcs in the reflect package to identify the core types in Hugo. For example, to identify an processable image hasn't been trivial, now it is:
{{ $obj := . }} {{ if reflect.IsResource $obj }} {{ if reflect.IsImageResource $obj }} // It has width/height and we can process it. {{ else }} // Just link to it. {{ end }} {{ end }}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。