Passing file from data folder to shortcode

Hi All! My first question in the forum. I’m not an advanced programmer developer so be gentle. I hope this isn’t answered somewhere else.

I have this shortcode:

{{< quote >}}

The testimonial file sits in the data folder and has this data structure.

first_last:
  name: First Last
  text: Quote
  type: Event
  cite: Reference to quote

This is an example of just accessing data in my shortcode. But I don’t know how to pass the data through the shortcode.

{{ with .Site.Data.testimonial.first_last }}
	{{ .text }}
	{{ .name }}
{{ end }}

I think the shortcode should look like this:

{{< quote file="testimonial" name="first_last" >}}

I’ve discovered I can do this thanks to @frjo

{{ $file := .Get "file" }}
{{ $name := .Get "name" }}
{{ $data := index .Site.Data $file }}
{{ with index $data $name }}
	<blockquote {{ with .cite }}cite="{{ . }}"{{ end }}>
		<p>{{ .text }}</p>
		<p>{{ .name }}</p>
	</blockquote>
{{ end }}

Any help appreciated! I’m getting there I’ve built my own theme from scratch so far but this is stumping me.

1 Like

Some good hints here:

1 Like

Wicked! That did it I’ve updated with my solution. Thank you @frjo

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