hello im trying to generate random posts/content in my sidebar widget, i made some research an i found that i have to use shuffle to do that, but i don’t know how to make it work can someone please help me by editing the code below, i tried doing it by my self but every time i push the changes if fails to build on netlify thank you in advance
{{- $recent := where .Site.RegularPages "Section" "in" .Site.Params.mainSections }}
{{- $recent_num := (.Site.Params.widgets.recent_num | default 10) }}
{{- if $recent }}
<div class="widget-recent widget">
<h4 class="widget__title">{{ T "recent_title" }}</h4>
<div class="widget__content">
<ul class="widget__list">
{{- range first $recent_num $recent }}
<li class="widget__item">
<a class="widget__link widget-recent__item" href="{{ .RelPermalink }}">
{{- if .Params.thumbnail }}
<img class="widget-recent__thumbnail" src="{{ .Params.thumbnail }}"/>
{{ .Title }}
{{- else }}
- {{ .Title }}
{{- end }}
</a>
</li>
{{- end }}
</ul>
</div>
</div>
{{- end }}
this what i use for showing 6 random quotes from press reviews with quotes, when I build the site.
Data from /data/fr/press.yml
{{ $datafr := index site.Data "fr" }}
{{ with $datafr.press }}
{{ if .enable }}
<!-- Affiche les revues de presse -->
<div class="row">
{{ range first 6 (where .item ".quote" "ne" nil) | shuffle }}
<div class="col-md-4 col-sm-6">
{{ with .web }}<h4>{{.}}</h4>{{ end }}
{{ with .quote }}<p>«{{.}}»</p>{{ end }}
</div>
{{ end }}
</div>
{{ end }}
{{ end }}
when i used range first and added shuffle in the end it worked but it only randomized the first posts and didn’t show the oldest one, and when i removed first i got this error 12:48:58 PM: Building sites … ERROR 2020/09/05 12:48:58 render of “page” failed: execute of template failed: template: _default/single.html:43:6: executing “_default/single.html” at <partial "sidebar.htm…>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/sidebar.html:9:13”: execute of template failed: template: partials/sidebar.html:16:6: executing “partials/sidebar.html” at <partial $p $root>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/widgets/recent.html:9:13”: execute of template failed: template: partials/widgets/recent.html:9:13: executing “partials/widgets/recent.html” at <$recent_num>: can’t give argument to non-function $recent_num
ERROR 2020/09/05 12:48:58 render of “page” failed: execute of template failed: template: _default/single.html:43:6: executing “_default/single.html” at <partial "sidebar.htm…>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/sidebar.html:9:13”: execute of template failed: template: partials/sidebar.html:16:6: executing “partials/sidebar.html” at <partial $p $root>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/widgets/recent.html:9:13”: execute of template failed: template: partials/widgets/recent.html:9:13: executing “partials/widgets/recent.html” at <$recent_num>: can’t give argument to non-function $recent_num
ERROR 2020/09/05 12:48:58 render of “page” failed: execute of template failed: template: _default/single.html:43:6: executing “_default/single.html” at <partial "sidebar.htm…>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/sidebar.html:9:13”: execute of template failed: template: partials/sidebar.html:16:6: executing “partials/sidebar.html” at <partial $p $root>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/widgets/recent.html:9:13”: execute of template failed: template: partials/widgets/recent.html:9:13: executing “partials/widgets/recent.html” at <$recent_num>: can’t give argument to non-function $recent_num
ERROR 2020/09/05 12:48:58 render of “page” failed: execute of template failed: template: _default/single.html:43:6: executing “_default/single.html” at <partial "sidebar.htm…>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/sidebar.html:9:13”: execute of template failed: template: partials/sidebar.html:16:6: executing “partials/sidebar.html” at <partial $p $root>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/widgets/recent.html:9:13”: execute of template failed: template: partials/widgets/recent.html:9:13: executing “partials/widgets/recent.html” at <$recent_num>: can’t give argument to non-function $recent_num
Total in 188 ms
12:48:58 PM: Error: Error building site: failed to render pages: render of “page” failed: execute of template failed: template: _default/single.html:43:6: executing “_default/single.html” at <partial "sidebar.htm…>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/sidebar.html:9:13”: execute of template failed: template: partials/sidebar.html:16:6: executing “partials/sidebar.html” at <partial $p $root>: error calling partial: “/opt/build/repo/themes/Feed/layouts/partials/widgets/recent.html:9:13”: execute of template failed: template: partials/widgets/recent.html:9:13: executing “partials/widgets/recent.html” at <$recent_num>: can’t give argument to non-function $recent_num