Hello. I have [params] in my config like this
[[params.reviews]]
id = 1
category = ["CDN"]
[[params.reviews]]
id = 2
category = ["Hosting", "CDN"]
[[params.reviews]]
id = 3
category = ["Hosting"]
How can I range this array with checking parameter “categoory”?
For example, on one page, I want to show only the parameters “CDN”.
there are many ways to do this!
but I would look at using a combo of range
and if
(see https://gohugo.io/templates/introduction/)
and you could get tricky with where
(see https://gohugo.io/functions/where/)
Okey. I tried like this
{{ range (where .Site.Params.reviews in "category" "CDN") }}
but something wrong (
My code in template is
{{ range (where .Site.Params.reviews in "category" "CDN") }}
{{ .id }}
{{ end }}
My config is
[[params.reviews]]
id = 1
category = ["CDN"]
[[params.reviews]]
id = 2
category = ["Hosting", "CDN"]
[[params.reviews]]
id = 3
category = ["Hosting"]
The error is
Building sites … ERROR 2019/09/02 23:12:40 render of "page" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\_default\cdn_features.html:1:37": execute of template failed: template: _default/cdn_features.html:286:3: executing "_default/cdn_features.html" at <partial "feedback_block" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\feedback_block.html:1:37": execute of template failed: template: partials/feedback_block.html:1:37: executing "partials/feedback_block.html" at <in>: wrong number of args for in: want 2 got 0
ERROR 2019/09/02 23:12:40 render of "section" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\section\cdn.html:1:37": execute of template failed: template: section/cdn.html:629:3: executing "section/cdn.html" at <partial "feedback_block" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\feedback_block.html:1:37": execute of template failed: template: partials/feedback_block.html:1:37: executing "partials/feedback_block.html" at <in>: wrong number of args for in: want 2 got 0
ERROR 2019/09/02 23:12:40 render of "page" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\_default\about.html:1:37": execute of template failed: template: _default/about.html:162:3: executing "_default/about.html" at <partial "feedback_block" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\feedback_block.html:1:37": execute of template failed: template: partials/feedback_block.html:1:37: executing "partials/feedback_block.html" at <in>: wrong number of args for in: want 2 got 0
ERROR 2019/09/02 23:12:40 render of "section" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\section\media-platform.html:1:37": execute of template failed: template: section/media-platform.html:592:3: executing "section/media-platform.html" at <partial "feedback_block" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\feedback_block.html:1:37": execute of template failed: template: partials/feedback_block.html:1:37: executing "partials/feedback_block.html" at <in>: wrong number of args for in: want 2 got 0
Total in 1818 ms
Error: Error building site: failed to render pages: render of "home" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\index.html:1:37": execute of template failed: template: index.html:280:3: executing "index.html" at <partial "feedback_block" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\feedback_block.html:1:37": execute of template failed: template: partials/feedback_block.html:1:37: executing "partials/feedback_block.html" at <in>: wrong number of args for in: want 2 got 0
Does this thread here help?