Select items from a pages list

I have a bunch of testimonials I want to show on different pages so I have set up a page with a blueprint like this:

—yaml
header.content.testimonials:
type: list
label: Testimonials

          fields:
            .quote:
              type: textarea
              label: Quote

            .name:
              type: text
              label: Name

            .type:
              type: select
              label: User type
              default: Customer
              options:
                customer: 'Customer' 
                yep: 'Yep'

            .category:
              type: text
              label: Kategori

So that I can manage all my testimonials on a single page. But then I want to be able to use these testimonials on different pages. Is there a blueprint type that I can use to select the testimonials I want from my testimonials page? Kind of the same way as the filepicker type.

You can just use page.find(/yoururl)
example if you want to display your testimonial on another page:

{% for item in page.find('/testimonials').header.content.testimonials %}
<h2>{{ item.name}}</h2>
<p>{{ item.type }} - {{ item.quote }}</p>
{% endfor %}

Am on mobile, so am not sure about the quotemark on pagefind!

Hope it helps!

If I only want a few of the testimonials? And pick those in the page? I have thought about having a list where I can specify they keys for the testimonials I want. But then I have to somehow store the testimonials as key values and as far as I have seen, the type array can only save strings?

Then I could have done something like

{% for testimonialId in page.header.content.testimonialIds %}
{% set t = page.find('/testimonials').header.content.testimonials[testimonialId] %}
<h2>{{ t.name}}</h2>
<p>{{ t.type }} - {{ t.quote }}</p>
{% endfor %}
---

Well, you can just add conditions

{% for item in page.find('/testimonials').header.content.testimonials if item.type == "customer" %}
<h2>{{ item.name}}</h2>
<p>{{ item.type }} - {{ item.quote }}</p>
{% endfor %}

Or if you want to pick them in the page:

{% set mychoice == page.header.testimonialselect %}
{% for item in page.find('/testimonials').header.content.testimonials if item.type == mychoice %}
<h2>{{ item.name}}</h2>
<p>{{ item.type }} - {{ item.quote }}</p>
{% endfor %}

Hmm, I think your solution with key value could work actually

Thanks, that would work. The content creators on the site isn’t that technical so it will be a bit hard for them to understand which testimonials they are selecting but it’s better then trying to maintain testimonials on every page.

I can’t get a blueprint to store anything else then a string for an array type…

@gyran
The content creators on the site isn’t that technical so it will be a bit hard for them to understand which testimonials they are selecting but it’s better then trying to maintain testimonials on every page

I see, maybe adding an explanatory text with the section field could help your user.
You could definitely write a plugin for this though.

Let me know if you make it work!

yes, thanks for your help! I’ll fiddle around a bit here and see where I land.

Do you know how you could save something else then a string in the array type?

What type of data would you want to store?

I would like to have the testimonials as the value of the array and the identifiers as the key

Something like

 testimonials:
  type: array
  fields: 
      .quote:
        type: textarea
        label: Quote

      .name:
         type: text
         label: Name

Then the key would be the identifier and the value would be the testimonial

page.find('/testimonials').header.content.testimonials[testimonialId].name
---