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 →

Reference field name from collection tag

Jeff Horii April 28, 2021 by Jeff Horii

I've created a partial that is supposed to dynamically show a list of entries from a collection.

In the UI, the editor can select a collection from the collection_name field.

My partial looks like this:

{{ collection[collection_name] }}
       {{ if featured_image }}<img src="{{ glide:featured_image width="405" height="250 fit="crop" }}" alt="{{ featured_image:alt }}">{{ /if }}
          <h3 class="mt-8">{{ title }}</h3>
          <p>{{ description }}</p>        
{{ /collection[collection_name] }}

I cannot get this to work. I don't get an error, just nothing is rendered from inside the collection tags. I've hard coded the collection name to make sure it works and it does. I've tried single quotes around it like ['collection_name']. Nothing.

I also added this field outside the collection tag to see the output and it was exactly as I needed it to be: "plan_a_visit"

I'm basing this approach off of the "Dynamic Access" section on this page

Any help with this would be much appreciated.

Answered by Jack McDade!
>>>>>>> Answered <<<<<<<
2 Replies