Exploring Bard Sets0:00
Next, I want to take you on a little bit of a deeper dive into the barred field type. We've used it to set up the basic news section of the site here, but we haven't gone into all of its capabilities, and they are so powerful and so much a core of the static experience that it would be a shame to not get a little bit deeper. So let's do that. We'll go to our collection, and we're going to edit the blueprint. In this case, it's our article content field. This is running barred. And we'll come down here to the sets section. Alright, so barred sets are basically fields within a field.
Configuring Set Fields1:40
So we'll strip this editor down as tight as it can go. We will save as HTML instead, so we don't have to loop through that. It'll just work like a standard HTML field type. And then maybe we'll even use the floating editor to keep the UI smaller. We'll automatically set target _blank on all links in case they go elsewhere. We'll do this, we'll add a couple of these on here, and that should really be enough. Next we'll have an author field, so that's going to be text. We'll call that author. And that will be our quote set.
Maybe we'll turn off the creation of new entries, because in this context it doesn't really make sense to be making whole new NewsArticle while writing a NewsArticle. And we will pick from other NewsArticle, entries inside the newsArticles collection. That is enough there. And then last but not least we'll do basically like an embed, which is a nice little utility field. And we'll use the template field type. We'll call it embedTemplate.
Testing Editor Changes3:25
And we'll use the template field type. We'll call it embed template. We don't want to hide partials, because this is probably what we want to embed. In fact, maybe we'll only show the contents of the partials directory. Okay, we're going to finish. We're going to save. And then let's go back to our collection. Open up one of these entries, and now you can see the differences that have happened here in the field type. So now when you start a new line, you'll have this
Looping Through Sets5:17
you know, newsletter signup or something like that. We'll save our entry. And then let's dive into the code. We'll go to the news.show template. And then here in the article.content field, we now need to loop through this because we have different nodes and blocks and sets to show. So we'll start by turning into a loop. And then we'll just put text here. And this will loop through and if it has a text field, it will render the text field. Which should give us what we have right now.
Conditional Set Rendering5:49
And this will loop through and if it has a text field, it will render the text field. Which should give us what we have right now. Let's give this a little refresh. But doesn't incorporate all the new sets. So the easiest way to do this is to just run some conditions. So if the type of set is text, render text. Else if type is quote,
And we'll leave it at that. Refresh and see what we've got going on. Alright, look at that. That is working. Tweak this, throw a little em dash in there. There we go. Maybe throw some quotes around the quote. And that's good for our quote set. Next if the type is related articles we can now loop through the related
Rendering Related and Embed7:25
related articles we can now loop through the related entries field that we set up. And this is essentially an entries tag. So we have access to all of that entries data right here. So we'll set up a link to the URL, title of the article, and then maybe just do a little related thing here. Set up a little class ahead of time. related block. Let's take a look. And there we go. Now I have a little
Related block. Let's take a look. And there we go. Now I have a little pull out for related articles. And last but not least else if type equals embed partial source and we'll pass it the embed template. That should render the footer right there and then again right there. But you understand. Art fields are really powerful and are really only limited to your creativity,
