Extracting News Card Partial0:00
Before we go too much further, let's dry up our templates a little bit. We've created some duplication between this news listing page and the taxonomy page. Let's jump into our code editor, go to the index page, and let's extract inside this collection news loop, let's extract that into a partial. So we'll cut, we'll go to partial, news, we'll call this card. Now we can create a card.antlers.html and put the contents of that template right there. If we refresh, everything should stay the same. Now this underscore prefix helps you to identify a template as being a partial versus a regular template, something you'd load a page with.
Now this underscore prefix helps you to identify a template as being a partial versus a regular template, something you'd load a page with. If you loaded a page with this template, that would be strange. Next we'll go to the tag show template, and that same markup was duplicated right here. So let's get rid of that. Partial, news, card. If we go to /tags, go to one of the tags on them, everything still renders. Now to have the tag inside the tag looks a little bit redundant, so let's pass a variable into that partial so we can turn that off. You can pass data into your partials and set it on the tag,
Passing Data Into Partials1:22
so let's pass a variable into that partial so we can turn that off. You can pass data into your partials and set it on the tag, so any variable name you make up, as long as it doesn't already exist, will get passed in without a problem. If it does exist, it'll overwrite it, so this allows you to stomp over data with your partial tag. Let's create a variable called hideTags. We're only showing one. hideTags singular is fine. And we'll say true. And we'll go to our card, and then we'll do unless hideTags,
And we'll say true. And we'll go to our card, and then we'll do unless hide tags, or if you want to, we could do if not hide tags, whichever you prefer. Let's indent that. Go back to our page. Singular. You know, naming stuff is hard. There we go. Just to demonstrate how to override, we could just set a title right here. Refresh, and it would stomp over the title that was inherited.
Reusing Home Page Panels3:50
Maybe we'll just add a limit of three to that collection loop. There we go. Looking pretty good. Next, let's extract these panels from the home page so that we can reuse them in a landing page template. Let's go to our home. Let's grab these panels. Create a new partial template. Clean up our line breaks. That still looks good.
