Resource

Height

返回给定图像资源的高度。

签名
RESOURCE.Height
返回类型
int

调用 Height 方法之前,请先用 reflect.IsImageResourceWithMeta 函数确认 Hugo 能否确定图像尺寸。

{{ with resources.GetMatch "images/featured.*" }}
  {{ if reflect.IsImageResourceWithMeta . }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ else }}
    <img src="{{ .RelPermalink }}" alt="">
  {{ end }}
{{ end }}