Hello. I have a params
[[params.reviews]]
text = ""
text_ru = "text"
text_de = "text 2"
text_cn = ""
and range
{{ $lang := .Lang }}
{{ range .Site.Params.reviews }}
How can I show only reviews with text? It should depend on .Lang.
For example,
for RU and DE it should be shown.
may be (untested) change for
[[params.reviews]]
lang = "xx"
text = ""
[[params.reviews]]
lang = "ru"
text = "text"
[[params.reviews]]
lang = "de"
text = "text 2"
[[params.reviews]]
lang = "cn"
text = ""
and
{{ range .Site.Params.reviews }}
{{ if .text }}
do what you need
{{ end }}
{{ end
Thank you.
This could be a solution, but it will be better if I don’t change the structure.
why ?
having only one [[params.reviews]]
doesn’t make real sense to me if you want to range over it.
It an example. I have 100+ params.reviews. But if this is the only way, then of course I will try your option.
OK. I get it.
May be you can try something like this (adapted from my code but untested) :
{{ $lang := .Lang | default "" }}
{{ $find_review := partial "find_review.html" (dict "context" . "lang" $lang ) -}}
Partial
{{ $lang := .lang }}
{{ $temp := .context.Param ( printf "text_.%s" $lang) }}
{{ $param_lang := .context.Param $temp }}
{{ return $param_lang }}
with
does not throw errors if something is “empty”.