Partial to variable and check whether variable contains anything

Hi all!

For several large projects I am switching from Middleman to Hugo and everything runs smoothly and very quickly. Thanks a lot for Hugo!

Just one more thing needs to work: How can I make a partial a variable and check whether it contains anything. Here the rough code:

{{ $myPartial := partial "mypartial.html" . }}
{{ if ($myPartial) and ($myPartial "!=" "") }}
<div class="myclass">
{{ $myPartial }}
</div>
{{ end }}

As mypartial.html contains if queries, ranges and such, it may contain empty spaces and line breaks.

Thanks a lot!

Try:

{{ with (partial "mypartial" .) }}
<div>
  {{ . }}
</div>
{{ end }}

Parentheses may be unnecessary.

Gosh. That is easy. Thank you very much.

I need to use

{{- with .Params.author -}}
{{ . }}
{{ end }}

in the partial, which looks odd to me—switching from ERB/HAML/SLIM … But it works.