New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Have collection in template read from a global

Kaz van Kooten March 19, 2019 by Kaz van Kooten

Alright, let me try to explain what I'm trying to do.

I have a collection called "staff", which contains approx. 30 people. This collection is shown on a page ("/our-staff") and every staff member has their own profile page.

I need to show which of these staff members are working today.

I've added a toggle field in the fieldset, so I could just have my client edit all collection items and either swipe the toggle on or off. My code on the "our staff"-page contains the following:

// partial.html

{{ collection:staff }}
{{ if working_today }}
<span>Working today</span>
{{ /if }}
{{ /collection:staff }}

That works, but it is a hassle to (potentially) have to edit 30 entries every day.

I'm puzzling with putting this information in a separate global:

// global_fieldset.yaml

    type: collection
    collection: staff

But now I have to somehow link this global to the items in the collection. So... if Person X is working today and I add him to the global, I would like to have the {{ collection }} on the page template read that and output something on that template.

Hope that this makes sense :-D

Answered by James Blair!
>>>>>>> Answered <<<<<<<
2 Replies