Reference page params in template from a variable name

I have the following data file in my site

"Castro": {
	"name": "Castro",
	"image": "Castro.svg",
	"description": "Listen in Castro.",
	"sortOrder": "2",
	"urlPrefix": "",
	"urlStyle": "iTunes",
	"feedIDParameter": "itunesfeedid"
"Google": {
	"name": "Google",
	"image": "Google.svg",
	"description": "Listen on Google.",
	"sortOrder": "3",
	"urlPrefix": "",
	"urlStyle": "custom",
	"feedIDParameter": "googlefeedid"
"Spotify": {
	"name": "Spotify",
	"image": "Spotify.svg",
	"description": "Listen on Spotify.",
	"sortOrder": "4",
	"urlPrefix": "",
	"urlStyle": "custom",
	"feedIDParameter": "spotifyfeedid"

I want to be able to use feedIDParameter to know which front matter parameter to look for in my template. I’ve figured out how to check if the parameter is set and compare it’s value, but I can’t figure out how to actually use that parameter in my template after that. Here’s my template code.

{{ range sort .Site.Data.listenOptions "sortOrder" "asc" }}
		{{- $feedID := "" -}}
		{{- if and (isset $this.CurrentSection.Params .feedIDParameter) (ne $this.CurrentSection.Params .feedIDParameter "") -}}
			{{- $feedID = $this.CurrentSection.Params  .feedIDParameter -}}
		{{- else if and (isset $this.CurrentSection.Parent.Params .feedIDParameter) (ne $this.CurrentSection.Parent.Params .feedIDParameter "") -}}
			{{- $feedID = $this.CurrentSection.Parent.Params .feedIDParameter -}}		
		{{- end -}}
		{{- if ne $feedID "" -}}
			{{ $feedID }}
			<a title="{{ .description }}" href="{{ .urlPrefix }}{{ $feedID }}">
				<div class="listen-option iconic-list-item">
					<img src="{{ $baseURL }}images/listen-buttons/{{ .image }}" />
					<p>{{ .name }}</p>
		{{- end -}}
	{{ end }}

This is the error I’m getting when I try to assign the parameter to the variable $feedID inside the body of my if statements.

execute of template failed: template: partials/listen-on.html:24:23: executing "partials/listen-on.html" at <$this.CurrentSection.Params>: wrong number of args for Params: want 0 got 1

I know what’s going on here, but not a way around the issue. It seems that the syntax “$this.CurrentSection.Parent.Params .feedIDParameter” works for comparatives in the conditional, but not when just trying to get the value of the parameter later.

Any help in how to actually get and use the parameter inside the body of the conditional is appreciated.

Actually I just finally figured this out. For others who may be curious or having the same problem…

I changed
{{- $feedID = $this.CurrentSection.Params .feedIDParameter -}}
{{- $feedID = $this.CurrentSection.Param .feedIDParameter -}}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.