On this Craft Cms lesson you'll learn how to query related data in your templates.
It has been the best investment I made in my design journey so far. I would consider myself a novice but I honestly feel like I've gained a genuine professional insight into the process of creating a high-level website.
I'm an early adopter of the KreativePro Masterclass, and I love how well put together it is. Neftali takes you through each step of the process from paper sketches to marketing all with fun visuals & clear instructions!
All right, guys. Welcome back to another lesson on Craft CMS. On this one, I just want to go over some of the ways we could filter related entries. And what I'd like to do is output all the related movies of this particular actor. Under the movies template, we're going to grab the grid. So if we toogle open the grid, we're going to see all that little snippets of code.
We're going to bring that over and then select it and copy it. And we're going to bring it over underneath the cast slideshow. We can remove those paginations, we don't need that. And for the conditional or the entries, we need to call it a new variable name because we're calling entries on movies. But in the cast now we're trying to fetch all the movies that are related to this particular actor.
Right. So in order for us to do that, we need to create a variable called related movies and call in craft entries. So the objects craft, and then the section to handle movies and just output all of the results. So let's swap out the title. So it should be "known for" in this case, the actor is known for, and let's change the variable in our for-loop to the one in the top of the document related movies.
So if we refresh, what's happening is now we're pulling absolutely every single movie. So the same idea from the movies template, but what we want to do is filter it by the actor. The way we do that is on the variable itself. So let's go ahead and add in the parameter called "related to", and inside of that, we're going to add in the entry object.
And as we know, the entry is the dynamic information of this actor itself. So we can see now, Elijah Wood is related to all these Lord of the rings movies. Awesome. .
Access our premium community including bonus tutorials, project files & weekly resources.UNLIMITED ACCCESS